简体   繁体   中英

Set Value of Property When Delete Key is Pressed in PropertyGrid

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 .

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; }

This is handled in the PropertyDescriptor .

You override ResetValue and CanResetValue .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM