How do I hide some of the default control properties at design-time (C#)?(如何在设计时 (C#) 隐藏一些默认控件属性?)
问题描述
我制作了一个自定义控件.它继承自 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#) 隐藏一些默认控件属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在设计时 (C#) 隐藏一些默认控件属性?


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01