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#) 隐藏一些默认控件属性?
基础教程推荐
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 如果条件可以为空 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
