Disable designer in Visual Studio?
Asked Answered
E

6

38

I'm using Visual C# Express to write Windows Form applications, and call me old school, but I don't like the designer. It is a nuisance and pollutes my project with lots of unwanted files, as well as unwanted monkey-generated source code.

Please tell me there's a way to turn it off completely.

Eduction answered 19/2, 2009 at 22:47 Comment(0)
B
2

Just dont add "new form" , add to the project new class and inherit him from the Form class.

Braxy answered 20/2, 2009 at 13:40 Comment(1)
I think this answer just changed my life. I can now write C++/CLI form applications the same way I would normally write Java, without having to use C#. I never thought of using C++/CLI without designer before, but it's beautifully powerful.Camiecamila
H
105

Add a [System.ComponentModel.DesignerCategory("")] attribute before a UI class to avoid designer activation on double-click.

Note that including System.ComponentModel at the top of the file and then just adding the attribute as [DesignerCategory("")] will not work (at least not in Visual Studio 2010/2013). You must use the full, namespace-qualified attribute type name.

Hindquarter answered 2/3, 2009 at 14:48 Comment(10)
You also seem to have to remove "<SubType>Form</SubType>" from the file's entry in the project file (e.g. .csproj file), at least in VS 2010Arielariela
I echo the comments from @wizlb for VS2012Encyst
In VS2013, it was "<SubType>Component</SubType>" rather than form, but Matt's point is correct. Nothing will happen otherwise.Ataractic
But how to enable designer for derived class? For example, I have [System.ComponentModel.DesignerCategory("")] class MyUserControl : UserControl{} and class MyDerivedFromMyUserControl: MyUserControl{} Is it possible to make first one non-designable, but make second one designable?Vibraculum
Set the [System.ComponentModel.DesignerCategory("Component")] attributeVibraculum
This is nice in that it works across teams and across reinstallations.Edom
Looks like just setting [DesignerCategory("")] in VS2015 is sufficient. Hooray!Genarogendarme
Works also great with VS 2015.Algometer
Works like a charm in VS17. This should have been the accepted answer.Priest
I do not like using "", used null instead and it's working! [System.ComponentModel.DesignerCategory(null)]Foppery
H
30

Right clicking on a project file and selecting open with allows you to set the defaults for opening file types.

Harwin answered 19/2, 2009 at 22:55 Comment(3)
OK, thanks, that's a big help. I didn't realize I could set the default opener for a file. It was a small nuisance to right click and pick "view code" every time.Eduction
This just showed me how to get rid of the SQL Design view stuff in Visual Studio 2012 and set it back to just opening it with a T-SQL Editor. Thanks, Richard from the past!Nitrobenzene
That's right but be careful. If you open the designer by accident, then it might mess up yourhandwritten code.Algometer
D
7

Actually, all you have to do in VS2010 is right click the .cs file that you don't want to open in the designer, select the "Open With.." option, then make CSharp Editor the default. Notice that the form view is the default before you change it.

Dynasty answered 26/11, 2011 at 19:37 Comment(1)
That's right, but then you could still accidentally open up the designer. I have a form where I strictly must prohibit invocation of the designer, because the designer is messing up the code.Algometer
B
2

Just dont add "new form" , add to the project new class and inherit him from the Form class.

Braxy answered 20/2, 2009 at 13:40 Comment(1)
I think this answer just changed my life. I can now write C++/CLI form applications the same way I would normally write Java, without having to use C#. I never thought of using C++/CLI without designer before, but it's beautifully powerful.Camiecamila
N
2

Frederik, sure you're right, but not in one fact. ( this one I.J wanted to know ) As soon as you inherit from any Component, the studio tries to open it in a designer editor. That is a default behaviour of the visual studio.

If you double click a file in the solution explorer, then a designer opens. So it's really annoying if you always get such strange designer for classes that are just inherited from a Component, but do not contain any visible things.

The only thing that really helped me out, was to set this attribute:[System.ComponentModel.DesignerCategory("")]

I didn't knew this =) so cool hint !

I just get a problem with partial MainForm classes. Then it yells "duplicate attribute"...

Does here anybody knows a solution to avoid in some partial class-files the designer to be opened on double click ( without the duplicate attribute error on compile ? )


I think I found a small bug, in VS2005... By setting the DesignerCategory-Attribute on the partial form class, on save the solution explorer shows up an icon, identifying the file as a c# file (no form).

Then I put a comment (//) before the attribute - and it keeps opening the file in code view. Also after closing and reopening it's stored internally as a non designable form-part. Even on re opening the complete solution.

So I think there is any information in the solution or project file...

... I found this in the .csproj file: ...

<Compile Include="GUI\VFormMain_Test.cs">
</Compile>
<Compile Include="GUI\VFormMain_Theme.cs">
</Compile>
<Compile Include="Core\VTTEnv.cs" />
<Compile Include="GUI\VFormMain.cs">
  <SubType>form</SubType>
</Compile>

...

Studio updates from time to time - then it updated the form files again (doh)... ok.. but there is probably a workaround to avoid this.


snip... last edit... found something:

http://social.msdn.microsoft.com/Forums/en-US/csharpide/thread/64c77755-b0c1-4447-8ac9-b5a63a681b78

( name the file you want to open without designer into .Designer.cs )

( Yes you have to name something to switch it of LOL ) Seems to work.

Needless answered 9/6, 2010 at 13:3 Comment(0)
N
-1

If you don't want to use the designer, then don't use it ?

You can create a new form from scratch, without the designer generating any code by creating a new empty class, and let the class inherit from System.Windows.Forms.Form

Then, VS.NET will probably still indicate that your class is a Form, and you can still open it up in the designer if you want. (And drop controls on it).

Nomanomad answered 19/2, 2009 at 23:3 Comment(1)
The problem is when it opens by default every time you open a specific file type.Craftwork

© 2022 - 2024 — McMap. All rights reserved.