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#) 隐藏一些默认控件属性?
基础教程推荐
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
