问题描述
我制作了一个自定义控件.它继承自 System.Windows.Forms.Control
,并具有我添加的几个新属性.是否可以显示我的属性(例如 TextOn 和 TextOff)而不是默认的Text"属性.
I have a custom control that I made. It inherits from System.Windows.Forms.Control
, and has several new properties that I have added. Is it possible to show my properties (TextOn and TextOff for example) instead of the default "Text" property.
我的控件工作正常,我只是想整理一下属性窗口.
My control works fine, I'd just like to de-clutter the property window.
推荐答案
您可以覆盖它们(如果它们可以被覆盖)并应用 Browsable
属性,指定 false
,或创建新版本的属性并应用相同的属性(第二种方法似乎并不总是有效,所以 YMMV).
You could either override them (if they can be overriden) and apply the Browsable
attribute, specifying false
, or create a new version of the property and apply the same attribute (this second approach doesn't always appear to work so YMMV).
此外,您可以使用自定义 TypeConverter
为您的类型并覆盖 GetProperties
方法来控制为您的类型显示哪些属性.这种方法对底层基类的变化更加稳健,但可能需要更多的努力,具体取决于您想要实现的目标.
Also, you can use a custom TypeConverter
for your type and override the GetProperties
method to control what properties get displayed for your type. This approach is more robust to the underlying base classes changing but can take more effort, depending on what you want to achieve.
我经常使用 Browsable
属性和自定义 TypeConverter
.
I often use a combination of the Browsable
attribute and a custom TypeConverter
.
这篇关于如何在设计时 (C#) 隐藏一些默认控件属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!