c# - 在 PropertyGrid 中按下 Delete 键时设置属性值

标签 c# winforms propertygrid design-surface

我目前正在从事一个托管 WinForms 设计器的项目。我正在使用 PropertyGrid 来显示放置在 DesignSurface 上的控件的操作属性。

我已经创建了 UITypeEditor 来修改我的自定义控件属性的值。

如何在 PropertyGrid 中按下 Delete 键时将属性值重置为 null

最佳答案

实际上,您所要做的就是将“DefaultValue”属性添加到您的属性中,并指定默认值为空。

例子:

[DefaultValue(typeof(Image), null)]
public Image MyLittlePicture { get; set; }

关于c# - 在 PropertyGrid 中按下 Delete 键时设置属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3830515/

相关文章:

c# - 如何枚举 PropertyGrid 项?

c# - 更改属性网格中只读属性的前景色

c# - 只可能用于特定类型?

c# - CLS 允许类中代码的私有(private)部分不符合 CLS。这怎么可能?

c# - 在 C# WinForms 中引发自定义事件

.net - .NET Winforms 组合框的显示格式为大写

c# - ListView.RetrieveVirtualItem 事件到底是什么 - C#

c# - 获取 CheckBoxList 项目值

c# - 具有继承类的属性列表的 PropertyGrid 编辑器

c# - 为什么我在 Active Directory 中创建用户时得到 "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"