4.7 Implementing Custom Properties
Many of the features we implement in the previous chapters of this chapter are implemented with the help of system-provided design-time metadata attribute support, such as:
Displays the Description property of the property description information
[Description ("Descriptive text")]
Specifies the category design property of a property in a category in the Properties window
[Category (Category name in Property window)]
Specify editor design properties for the property editor
[Editor (typeof (Filenameeditor), typeof (UITypeEditor))]
Specify the TypeConverter design properties of the property type converter
[TypeConverter (typeof (Solidcoordinateconverter))]
These are provided by the system, and each property has its own function. So what if we want to customize a design attribute and implement a custom function? To design a custom attribute, you only need to derive it directly or indirectly from System.Attribute, exactly as the traditional class feature does. We can either use System.Attribute to define control design period control or use System.Attribute to specify Run-time control.
This section demonstrates how the design properties in the control are implemented as an example. First, let's explain the functionality that this section controls properties to implement, as shown in Figure 4-35.
This control has a num property that allows developers to specify a value. A validation property of the Numvalidate type is specified on the control's properties, which requires that two parameters be passed in for the developer to specify an interval, and a warning prompt (such as the red warning hint in Figure 4-36) is provided if the property specified in the Properties window is not within the range.
Figure 4-36 Example of control design properties