Extender providers add properties to other controls. The ActiveX world also had the concept of extender providers, however, special support was required in the programming language to support them. In the NGWS frameworks, no special language support is required for extender providers. In source code, an extender provider property exists on the actual extender provider object. Setting the value of the property on another object requires two pieces of information: the object to set the value on, and the new value of the property. For example, Win Forms has a ToolTip component that offers an extender property to other controls. The property it sets on other objects is a string that represents the tool tip the user sees when she hovers her mouse cursor over the control. The source code for setting the tool tip property on a control is shown below:
[C#] tooltip1.SetToolTip(button1, “The tooltip text”);
At design time, extender properties show up in the property browser as properties on objects they extend, rather than the actual extender object. In the example above, the ToolTip property shows up on button1
, not on tooltip1
.
To implement an extender provider
[C#] public MyExtender : IExtenderProvider {...}
The definition of IExtenderProvider is given below.
[C#] public interface IExtenderProvider { bool CanExtend(IComponent component); }
Note An ExtenderPropertyAttibute must be applied to an extender property.
[C#] [ DefaultValue(""), ExtenderProperty(typeof(Control)) ] //The Get method needs an attribute since it tells the //designer to display this property. public string GetHelpText(Control control) {...} //The Set method does not need an attribute. public void SetHelpText(Control control, string value) {
While an extender provider implemented as above can provide properties to any component, the implementation is often not so general, but includes features that make it usable only with a specific category of components.
Note The implementation of an extender provider for Win Forms controls is different from that for Web Forms controls.
A complete sample is provided in Win Forms Extender Provider Sample.