如何隐藏一些在设计时(C#)的默认控件属性呢? [英] How do I hide some of the default control properties at design-time (C#)?

查看:123
本文介绍了如何隐藏一些在设计时(C#)的默认控件属性呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的控制,我做。它继承自 System.Windows.Forms.Control的,并且具有我已经添加了几个新的属性。是否有可能显示,而不是默认我的属性(纹元和TextOff为例)文本属性。

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.

推荐答案

您既可以覆盖它们(如果​​它们可以被覆盖),并应用<一href="http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx"><$c$c>Browsable属性,指定,或创建属性的新版本,并采用相同的属性(这第二种方法并不总是似乎工作,所以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).

此外,您还可以使用自定义的<一个href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverter.aspx"><$c$c>TypeConverter为你的类型和覆盖<一href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverter.getproperties.aspx"><$c$c>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.

我经常使用的<一个组合href="http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx"><$c$c>Browsable属性和一个自定义的<一个href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverter.aspx"><$c$c>TypeConverter.

I often use a combination of the Browsable attribute and a custom TypeConverter.

这篇关于如何隐藏一些在设计时(C#)的默认控件属性呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆