[英]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.今天我注意到,Visual Studio 2008 总是将文件视为组件或表单,如果该文件包含一个定义。
This means 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.
我认为这种行为很烦人,因为包含源自表单或控件的 class 的文件不一定是实际的表单或控件,我想默认编辑源。
I'll just repeat the solution I found at http://social.msdn.microsoft.com/Forums/da/winformsdesigner/thread/cdfd7e6f-3ffc-4969-9ce1-c1ca0f08ae67我将重复我在http://social.msdn.microsoft.com/Forums/da/winformsdesigner/thread/cdfd7e6f-3ffc-4969-9ce1-c1ca0f08ae67找到的解决方案
Add the DesignerCategory attribute to your class like this:像这样将 DesignerCategory 属性添加到 class 中:
[System.ComponentModel.DesignerCategory("")]
public class Foo : FormDerivedClass
A class that derives from Form
will always be a Form
;从
Form
派生的 class 将始终是Form
; this is a fundamental concept of object orientation.这是 object 方向的基本概念。 That said, you can alter the default behavior:
也就是说,您可以更改默认行为:
Right click on the file, Open With, select preferred editor from the list, Set as Default.右键单击文件,打开方式,列表中的 select 首选编辑器,设置为默认值。 Although this works for all files of that type, not for a single file.
尽管这适用于该类型的所有文件,但不适用于单个文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.