Browse DevX
Sign up for e-mail newsletters from DevX


Breathe New Life into Old Controls with ExtenderProviders






rom the beginning, the Tag property has been a Visual Basic programming staple. Any time you want to attach a little extra bit of information, you can put it in the Tag property. In .NET, the Tag property became even more useful, allowing you to store objects rather than just strings.

While Tag is great, there are times when it's just not quite enough. What if you're working on a large project and some other developer needs to use the same Tag property for something else? You could store a collection in the Tag property where you can both put values but that requires extra coordination. Or you could subclass the control to add an extra property to it, but that would give you a whole new class to debug and maintain. Wouldn't it be nice if you could just add an extra Tag property to a control for your own private use?

With ExtenderProviders you can! An ExtenderProvider is a component that adds any sort of extra service to existing controls and components. The ErrorProvider, HelpProvider, and ToolTip components are all provider classes that come with Visual Studio. When you add a ToolTip component to a form, for example, it provides a new ToolTip property to all the controls on the form. If the ToolTip component is named ToolTip1, then you'll see that every control on the form magically acquires a property—a new property called ToolTip on ToolTip1. This name means that the ToolTip1 component is providing a ToolTip property.

It's not too hard to add your own ExtenderProviders to add extra properties and behaviors to existing controls.
