R – Adding “Reset” Command to a Control’s Extended Property in Property Grid

design-timenetwinforms

I have an Extender component of IExtenderProvider which extends a TextBox to have a "selected color". The default value for this color is "highlight". The user can change the "default selected color" in the Extender's property grid. If no extended TextBox has "selected color" defined, it will use the specified "default deleted color" value.

If the programmer has changed a TextBox's "selected color", I want to provide the "reset" command in the property grid that resets the "selected color" to the "default selected color", as define in the Extender component.

How do I add the "reset" command to the extended control's property grid value then "reset" that extended property to the default value provided by the extender?

I want to allow the user to right-click on the extended property and choose Reset to restore the property to its default value as defined in the extender.

(See Defining Default Values with the ShouldSerialize and Reset Methods at http://msdn.microsoft.com/en-us/library/53b8022e.aspx)
Obviously, this is not going to work.

Public Sub ResetGetMyProperty()
    MyProperty = "Hello World!"
End Sub

And I cannnot use the following because this is for the "reset" on the Extender's property.

Public Sub ResetMyProperty()
    MyProperty = "Hello World!"
End Sub

I cannot use DefaultValue, as shown below, because it requires a constant, which is not the case because the programmer can change the default value.

<DefaultValue("Hello World!")> _
Public Sub GetMyProperty(control As Control) As String
    Return _extendees(control).MyProperty
End Sub

I need something like <DefaultValue(Me.Property)> because Me.Property is the value specified by the programmer through the property grid. (Which I cannot do, because Me.Property is not a constant.)

[clarification]
The extender itself has properties. These are the default values for any extended control. If a programmer does not specify an "override" value for a specific extended control, then the default value will be use. I, as the author of the extender, default to a specific value, say "highlight", but you, the user of my extender, want to default to "red", you will have to change the extender's property. Now any extended controls, which did not define this extended property will use "red". Yet, any control that have specified a value…cannot "reset" to this "red". DefaultValue doesn't apply. (Currently, the only way to set the default is to delete the code from the designer.)

Any suggestions?

Note that I do not use Color in the code fragments above because it clutters up what I am trying to illustrate.

Best Answer

The reset method signature for extended property is:

Public Sub ResetMyProperty(control As Control)
    MyProperty = "Hello World!"
End Sub

Do similar thing to ShouldSerializeValue method by adding a control parameter.

Related Topic