[英]Is there an attribute I can add to a class so it will be edited as code, not in the designer?
I've made a class which inherits from UserControl, but which I only want to use as a base for subclasses. 我创建了一个继承自UserControl的类,但我只想将其用作子类的基础。 Is there a way I can stop VS2008 from trying to edit it in the designer, that won't stop the subclasses from being edited in the designer?
有没有办法阻止VS2008在设计器中编辑它,这不会阻止子类在设计器中被编辑?
There is. 有。 I believe if you have multiple classes in a file, VS looks at the first one only, but I may be mistaken.
我相信如果你在一个文件中有多个类,VS只看第一个,但我可能会弄错。 In any case, this should do the trick:
在任何情况下,这应该做的伎俩:
[System.ComponentModel.DesignerCategory("Code")]
public class SomeBaseClass : UserControl
{
//...
}
Note that in versions of Visual Studio prior to 2017, you must use the full name of the attribute as shown above. 请注意,在2017年之前的Visual Studio版本中,您必须使用属性的全名,如上所示。 If you try putting a using statement above it and simply trying "DesignerCategory" visual studio may not honor it.
如果您尝试在其上面放置一个using语句并且只是尝试“DesignerCategory”,那么visual studio可能不会尊重它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.