views:

332

answers:

2

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.

A: 

You can use the DefaultValue attribute, using the name of the system color setting that you want as default value:

<DefaultValue(GetType(Color), "Highlight")>
Fredrik Mörk
As noted in question, "Highlight" is a constant. It does not reflect the color specified as the "default selected color" by the programmer.
AMissico
@AMissico: what do you mean by "default selected color"? "Highlight" will map to the color that is currently defined by the system colors (which are selectable by the user).
Fredrik Mörk
Yes, but 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 color property will use "red". Yet, any control that have...cannot "reset" to this "red". DefaultValue doesn't apply.
AMissico
@AMissico: now I understand (I interpreted the "default selected color" as the system defined one).
Fredrik Mörk
Thank for your discussion. I added my last comment as a "clarification" to the question.
AMissico
A: 

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.

Kenneth Xu
You are AWESOME! Is there documentation for this?
AMissico
There is no specific document for extender provider on this. At least I didn't find any. But I guess you already know about the reset support for regular property. In case of extender provider, in order for VS designer support to tell you which control to reset, by nature it has to pass the control to you. That's how I figured out the signature.
Kenneth Xu