How to use Attribute in the Development of C # WinForm Control
This article mainly shows you "Attribute in C # WinForm control development how to use", the content is easy to understand, clear, hope to help you solve doubts, the following let Xiaobian lead you to study and learn "how to use Attribute in C # WinForm control development" this article.
An example of the use of Attribute in the Development of C # WinForm Control
This class is derived directly from the Control class, and custom controls are derived directly from the Control class. This class defines a property TextAlignment that controls where the text is displayed in the control:
[Category ("Alignment"), Description ("Specifies the alignment of text.")] public ContentAlignment TextAlignment {get {return alignmentValue;} set {alignmentValue = value; / / The Invalidate method invokes the OnPaint method described / / in step 3.Invalidate ();}}
There are two Attribute on top of this property, which describe the characteristics of the control at design time. Let's take a look at the design-time Attribute that is mainly used in control design.
The properties used by Attribute in the development of C # WinForm controls:
◆ BrowsableAttribute: describes whether a property or event should be displayed in the property browser.
◆ CategoryAttribute: a category that describes a property or event. When a category is used, the property browser groups properties by category.
◆ DescriptionAttribute: when the user selects an attribute in the property browser, the text specified in the description will be displayed below the property browser, showing the function of the property to the user.
◆ BindableAttribute: describes whether an attribute tends to be bound.
◆ DefaultPropertyAttribute: specify a default property for the component. When the user selects a control on the Form designer, the default property is selected in the property browser.
◆ DefaultValueAttribute: sets a default value for a property of a simple type.
◆ EditorAttribute: specify a special editor for the attribute.
◆ LocalizableAttribute: indicates whether an attribute can be localized, and any property with this Attribute will be persisted to the resource file.
◆ DesignerSerializationVisibilityAttribute: indicates whether or how an attribute is persisted into code.
◆ TypeConverterAttribute: specifies a type converter for the attribute, which converts the value of the property into other data types.
◆ DefaultEventAttribute: specifies a default event for the component, which is selected in the property browser when the user selects a control in the form design.
These design time Attribute is very important, if used well, it will bring great convenience to the user.
The above is all the contents of the article "how to use Attribute in the development of C # WinForm controls". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!