怎么给所有控件添加自定义的属性

如何给所有控件添加自定义的属性?
就像tooltip控件,也就是在设计环境中往窗体中添加tooltip控件,该窗体中所有的控件都会增加tooltip属性,设置tooltip的显示内容,这是如何实现的?


------解决方案--------------------

这个的实现其实不难,可以参考下面的TT这个类的实现。
主要是三点做到就可以了:
1:为要实现的类添加ProvidePropertyAttribute属性
2:类要继承于IExtenderProvider接口并实现其接口成员
3:要实现ProvidePropertyAttribute的PropertyName的Get及Set方法

参考实现类如下:

[ProvideProperty("TT", typeof(Control))] 
class tt : Component, IExtenderProvider
{
public bool CanExtend(object target)
{
return ((target is Control) && !(target is tt));
}

[DefaultValue(""), Localizable(true), Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public string GetTT(Control control)
{
if (control == null)
{
return string.Empty;
}
return "测试测试";
}
public void SetTT(Control control, string caption)
{

}
}