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#) 隐藏一些默认控件属性?
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
