Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Extender Provider Objects

An extender provider is a component that provides properties to other components. For example, when a ToolTip component is added to a form, it provides a property called ToolTip to each control on that form. The ToolTip property then appears in the Properties window for each control and allows the developer to set a value for this property at design time.

The property provided by the extender provider actually resides in the extender provider object itself and therefore is not a true property of the component it modifies. At design time, the property will appear in the Properties window for the component that is being modified. At run time, however, the property cannot be accessed through the component itself. In the following code example, a form has been created with a button called MyButton and a ToolTip control called MyToolTip, which provides a ToolTip property.

// This is an example of code that is NOT CORRECT!
string myString;
myString = MyButton.ToolTip;

This syntax will generate a compile error because the compiler does not recognize ToolTip as a property of MyButton, because the property is actually provided by MyToolTip. The following example shows how to correctly access that property:

string myString;
myString = MyToolTip.GetToolTip(MyButton);

The extender provider is a class, and as such can have its own properties and methods. In order to designate a property as the property to be provided to other components, you apply the ProvidePropertyAttribute attribute at the class level. This attribute specifies the name of the property to provide and the type of object it can provide that property to. By convention, the property provided is not implemented as a property, but rather as a pair of methods. These methods must have "Get" and "Set" added to the beginning of the name of the property to be provided. The following example shows how.

using System.ComponentModel;
[ProvideProperty("MyText", typeof("Control"))]
public class MyExtender
   public string GetMyText(Control acontrol)
      // Insert code to implement method.
   public void SetMyText(Control acontrol)
      // Insert code to implement method.

The implementation of the provided property will require a Hashtable or some other such collection object to record and retrieve the property values for each control. For details, see How to: Implement an Extender Provider.

Every extender class must also implement the IExtenderProvider interface. This interface consists of a single method, CanExtend, which returns a Boolean value and indicates to the designer whether a component is a candidate to be extended or not. For example, you might want to create an extender that provides a property only to controls. The following example shows how to implement the CanExtend method:

public bool CanExtend(object extendee) 
   if (extendee is Control)
      return true;
      return false;

See Also

Community Additions

© 2015 Microsoft