The vs2003 designer has an interesting feature: During winform design, the control has no tooltip. To add a toolbox, You need to drag a special tooptip control from the toolbox, at this time, a tooltip attribute will be added to all controls on the screen, which looks cool.
It is easy to make such a control:
[Provideproperty ("XXX", typeof (system. Web. UI. Control)]
The attribute to be dynamically added here is XXXX, and the target is all control controls.
Add several attributes before the control class and there will be several dynamic attributes.
Public Class Cultureselector: dropdownlist, iextenderprovider
{
Public Bool Canextend ( Object Extendee)
{
ReturnExtendee! = This &&ExtendeeIsWebcontrol;
}
}
The iextenderprovider interface must be declared on the control class. Perform detailed filtering in the canextend method. For example, you only want to add dynamic attributes to textbox.
[Description ( " Allowed attributes " )]
[Category ( " Culture " )]
Public String [] Getxxx (Control)
{
}
Public Void Setxxxx (Control, String [] Value)
{
}
The dynamic attribute operation will call the aboveCode. Note:
1. The control parameter must be consistent with the preceding statement.
2. getxxx/setxxxx must be consistent with the preceding attribute declaration. If it is missing, it will become read-only.
3. the return value of getxxx must be of the same type as that of setxxx. Type is not limited.
4. Add [category] [description] and so on to getxxx. The usage is consistent with the actual attribute.
Add the above Code to an existing control. This control dynamically adds attributes to other controls at runtime.