How to keep Visual Studio from treating files as components or forms
Today I noticed that Visual Studio 2008 always treats a file as if it was a component or a form if this file contains a definition of one.
This mean开发者_运维技巧s that it always opens the designer by default. I think this behavior is very annoying, because a file containing a class that derives from form or control does not have to be an actual form or control and I want to edit the source by default.
I'll just repeat the solution I found at http://social.msdn.microsoft.com/Forums/da/winformsdesigner/thread/cdfd7e6f-3ffc-4969-9ce1-c1ca0f08ae67
Add the DesignerCategory attribute to your class like this:
[System.ComponentModel.DesignerCategory("")]
public class Foo : FormDerivedClass
A class that derives from Form
will always be a Form
; this is a fundamental concept of object orientation. That said, you can alter the default behavior:
- Right-click the file in question, select "Open with..." in the context menu
- In the dialog, select "Source code (Text) editor..."
- Click the "Set as default" button
- Click OK
Right click on the file, Open With, select preferred editor from the list, Set as Default. Although this works for all files of that type, not for a single file.
精彩评论