简体   繁体   English

是否有可以添加到类中的属性,因此它将被编辑为代码,而不是在设计器中?

[英]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.

相关问题 如何创建具有可在设计器中编辑的IPAddress属性的控件? - How can I create a control with IPAddress properties that can be edited in the designer? 我可以通过属性将代码添加到方法吗? - Can I add code to a method via an Attribute? 如何在单独的 class 中为方法覆盖或添加属性,以便刷新 WCF 服务不会影响我的更改? - How can I override or add an attribute to a method in a separate class so that refreshing a WCF service doesn't blow away my changes? 如何添加自己的代码以及表单设计器生成的代码? - How can I add my own code along with the code generated by the form designer? 我可以将一个类标记为不是我的代码,以便调试器逐步执行吗? - Can I mark a class as not my code so the debugger steps over it? 在派生类中重写Designer属性 - Overriding Designer attribute in derived class 我可以在 Visual Studio 中添加一个 C# 类作为资源,以便我可以方便地添加到新项目中吗? - Can I add a C# class in visual studio as resource so I can add to new projects conveniently? 如何从ViewModel将已编辑图像添加到ListView? - How I can add edited images to ListView from a ViewModel? 每当我添加新控件时,都会更改 WinForms 设计器代码 - The WinForms designer code is changed whenever I add new control 如何添加到这样的类中,以便进行foreach循环? - How can I add to a class like this so I can foreach loop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM