Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I assign a function or property to all of other classes just like ToolTip

Tags:

c#

tooltip

When I drag and drop a ToolTip object on my form in C#, every control on the form gets a new property called ToolTip which didn't exist before. I'm trying to create something just like ToolTip so that when I drag and drop it onto my form all of the controls will automatically get its new property.

I would also be grateful if anyone could give me a definition for this so that I can edit my question to convey my intention and meaning better.

like image 204
Hossein Avatar asked Aug 27 '12 17:08

Hossein


2 Answers

What you are looking for is an "Extender Provider". Very simply, you don't actually add the new property to the controls' grids. You instead implement an interface that the VS designer looks for, that tells VS how to "transform" the property set in the grid to a call to the Extender Provider to really do the trick.

In addition to ToolTips, LayoutPanels like TableLayoutPanel and FlowLayoutPanel do similar things, as well as certain other "meta-window components".

like image 117
KeithS Avatar answered Nov 11 '22 08:11

KeithS


ToolTip is an Extender Provider. The full documentation for implementing it is here, with a full example here.

ToolTip would likely be implemented like this:

[ProvideProperty("ToolTip", typeof(IComponent))]
class ToolTip : IExtenderProvider {...}
like image 43
Austin Salonen Avatar answered Nov 11 '22 08:11

Austin Salonen