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

家住魔仙堡 提交于 2019-12-10 13:48:34

问题


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.


回答1:


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".




回答2:


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 {...}


来源:https://stackoverflow.com/questions/12146708/how-can-i-assign-a-function-or-property-to-all-of-other-classes-just-like-toolti

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!