在 PropertyGrid 中按下删除键时设置属性值

发布于 2024-09-25 05:41:05 字数 240 浏览 0 评论 0原文

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

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

当在 PropertyGrid 中按删除键时,如何将属性值重置为 null

I am currently working on a project that hosts WinForms designer. I am using PropertyGrid to display manipulate properties of the controls that are dropped on the DesignSurface.

I have created UITypeEditor's to modify values of my custom controls properties.

How can I reset the value of the property to null when Delete key is pressed in the PropertyGrid.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月棠 2024-10-02 05:41:05

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

例子:

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

Actually, all you have to do is add the "DefaultValue" attribute to your property and specify that the default value is null.

Example:

[DefaultValue(typeof(Image), null)]
public Image MyLittlePicture { get; set; }
南薇 2024-10-02 05:41:05

这是在 PropertyDescriptor 中处理的。

您可以覆盖 ResetValueCanResetValue

This is handled in the PropertyDescriptor.

You override ResetValue and CanResetValue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文