Use of System.Windows.Forms.PropertyGrid

Source: Internet
Author: User

Introduction to PropertyGrid Controls

The. NET Framework PropertyGrid controls are at the heart of the Visual Studio. Net Property Browser. The PropertyGrid control displays the properties of an object or type, and retrieves the properties of an item primarily by using reflection. When we create a class compile, we generate the Metadataof the class, the metadata. PropertyGrid is the property of public identity that uses reflection to present and modify the common properties of a class. Whenever mature software is configured to meet the needs of different scenarios or customers, it is the use of parametric switches. PropertyGrid represents the mainstream of the configuration interface, for the implementation of training of technical support staff more humane. Share your experience with me now.

Selectedobject

The PropertyGrid method Selectedobject is to get or set the object that displays the properties in the grid. Is the most important way to display objects using PropertyGrid.

Actual Use Cases

key points to use :

    • 1) If the property value is an enumeration type, the drop-down box and the fill selection value are automatically generated when the property is changed.
    • 2) attributes can be custom categorized
    • 3) attributes can be commented and explained
    • 4) Property settings Customizable property types
    • 5) If you need to hide a property that is not displayed in PropertyGrid, you can mark [Browsable (false)] on the property of the class.
Private string _ dynamic content;        [Description (@ "format: {propertyname[(Start[,length])]}[&blank[(Length)]]&{propertyname[(Start[,length])]}                         PropertyName: Options                        in Dynamic properties Start: The starting position of the dynamic property corresponding content length                        : The length of the intercepted content                        blank: space length                        : The number of spaces                        &:                        When setting this content for separators, be careful The system does not detect the legality of its value when it is set, it may error "when executing"), Category ("expression")]        [XmlAttribute ("Dynamic Content")] public                string dynamic content        {            Get {return _ dynamic content;}            Set {_ Dynamic content = value; Notifypropertychanged ("dynamic content"); }        }

To change the way some properties are displayed, you can apply different attributes to those properties. Attributes are declarative tokens used to annotate programming elements such as types, fields, methods, and properties, which can be retrieved at run time using reflection. Some of these are listed below:

DescriptionAttribute -Sets the property text displayed in the Description Help pane below the properties. This is an efficient way to provide help text for an activity property (that is, a property with focus).

CategoryAttribute -Sets the category to which the property belongs in the grid. This feature is useful when you need to group properties by category name. If no category is specified for the attribute, the property is assigned to the miscellaneous category. You can apply this attribute to all properties.

BrowsableAttribute – Indicates whether the property is displayed in the grid. This attribute can be used to hide properties in the grid. By default, public properties are always displayed in the grid.

ReadOnlyAttribute – Indicates whether the property is read-only. This attribute can be used to disallow editing of properties in the grid. By default, public properties with get and set access functions can be edited in the grid.

DefaultValueAttribute – Represents the default value for the property. Use this attribute if you want to provide a default value for the property, and then determine whether the property value is the same as the default value. You can apply this attribute to all properties.

Defaultpropertyattribute – Represents the default property of the class. When you select a class in the grid, the default properties of the class are highlighted first.

  

For Custom PropertyGrid properties , please refer to the article: http://blog.csdn.net/jjhua/article/details/23100143.

All right. Do not write a little flustered. But it takes a lot of time to write well. Just hold on a minute.

Use of System.Windows.Forms.PropertyGrid

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.