Create a custom class that implements the iextenderprovider Interface

Source: Internet
Author: User
Tags building windows

Why iextenderprovider

By implementing the iextenderprovider interface, control can extend its attributes to other controls to applyProgramProvides richer, faster, and more powerful performance at design time and runtime.

What is iextenderprovider

Iextenderprovider is an interface that defines attributes to be extended to other control. The iextenderprovider has only one canextend method member and returns a Boolean value.
The classes implementing iextenderprovider in. Net include componenttray, errorprovider, helpprovider, localizationextenderprovider, propertytab, and tooltip. In Windows Forms design, classes such as errorprovider and tooltip are often used.
For more information about iextenderprovider, see the msdn help.
MS-help: // Ms. msdnqtr.2003feb. 2052/cpref/html/frlrfsystemcomponentmodeliextenderproviderclasstopic.htm

How to Use iextenderprovider

To create a custom iextenderprovider extension class, you need to take the following steps to better specify the points,ArticleThe following uses tooltip as an example to describe how to implement iextenderprovider:
1. reference the system. componentmodel namespace;
[C #]

Using System. componentmodel;

[VB. NET]

Imports System. componentmodel

2. Implement the iextenderprovider interface in the Custom class;
[C #]

Public   Class Tooltip: component, iextenderprovider {
}

[VB. NET]

Public   Class tooltip ClassTooltip
 InheritsComponent
 ImplementsIextenderprovider
End Class

3. Use the attribute feature of provideproperty to expand attributes externally;
[C #]

[Provideproperty ("tooltip ", Typeof (Control)]
Public   Class Tooltip: component, iextenderprovider {
}

[VB. NET]

< Provideproperty ("tooltip ", GetType (Control )) > _
Public   Class tooltip ClassTooltip
 InheritsComponent
 ImplementsIextenderprovider
End Class

4. Implement the canextend method of the iextenderprovider interface and define the type of control that can be extended;
[C #]

Public   Bool Canextend ( Object Extendee) {
//More code here.
}

[VB. NET]

Public   Function canextend () FunctionCanextend (extendeeAs Object)As Boolean
 'More code here.
End Function

5. Implement public attributes.
Get propertyname
[C #]

Public   String Gettooltip (control extendee) {
//More code here.
}

[VB. NET]

Public   Function gettooltip () FunctionGettooltip (extendeeAsControl)As String
 'More code here.
End Function

Set propertyname
[C #]

Public   Void Settooltip (control extendee, String Value) {
//More code here.
}

[VB. NET]

Public   Sub settooltip () SubSettooltip (extendeeAsControl, ValueAs String)
 'More code here.
End sub

The propertyname must be the same as the property name exposed by provideproperty in 3rd. We can see that the attribute is not implemented through the get/Set construction block, but instead replaced by methods. This is a bit like implementing attributes in Java.
The type returned by the get method is the same as the type of the property to be extended by the custom class in the set method. It can be numeric, numeric, or even enumeration.

Conclusion

In the process of creating your own iextenderprovider class, I made many attempts and made many detours. Finally, I summarized the following suggestions. It should be declared that these suggestions are not mandatory, nor are Microsoft's official suggestions for implementing the iextenderprovider interface (at least I have not found any relevant information). However, according to the principle of this suggestion, this allows your custom controls to have better readability and maintainability.
Suggestions for implementing the iextenderprovider interface are as follows:
1. The class implementing iextenderprovider should be independent, and it should only inherit from component, rather than other controls;
2. Classes implementing iextenderprovider should exclude themselves when returning canextend, that is, they should not be used as extensible objects;
3. The extended attributes provided by the class implementing iextenderprovider should be clear and self-explanatory;
4. All references to extended control in the class implementing iextenderprovider should be represented using the extendee variable whenever possible.

References

1. msdn library. NET 2003,
2. building Windows Forms controls and components with rich design-time features, Michael weinhardt and Chris sells
3. reflector. net, Lutz roeder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.