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.
Right clicking on a project file and selecting open with allows you to set the defaults for opening file types.
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.
Just dont add "new form" , add to the project new class and inherit him from the Form class.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With