Take full advantage of the PropertyGrid control (Microsoft) VI of the. NET Framework

Source: Internet
Author: User
Tags integer advantage
Controls | Microsoft changes how properties are displayed
To change the way some properties are displayed, you can apply different attributes to these properties. Attributes are declared tokens that are used to annotate programming elements such as types, fields, methods, and properties, and can be retrieved using reflection at run time. Some of these are listed below:

DescriptionAttribute-Sets the property text that appears in the Description Help pane below the property. This is an effective way to provide help text for active properties, which are the properties that have focus. You can apply this attribute to the maxRepeatRate property.
CategoryAttribute-Sets the category to which the property belongs in the grid. This attribute 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. You can apply this attribute to the Settingschanged property.
readonlyattribute– indicates whether the property is read-only. This attribute can be used to prevent editing of properties in the grid. By default, public properties with get and set access functions are editable in the grid. You can apply this attribute to the AppVersion property.
defaultvalueattribute– represents the default value for a property. You can use this attribute if you want to provide a default value for a 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 a class. When you select a class in the grid, the default properties for that class are highlighted first. You can apply this attribute to the AppSettings class.
Now, we apply some of these features to the AppSettings class to change how properties are displayed in PropertyGrid.

' Visual Basic

<defaultpropertyattribute ("saveOnClose") > _
Public Class AppSettings
Private _saveonclose as Boolean = True
Private _greetingtext as String = "Welcome to the application!" "
Private _maxrepeatrate as Integer = 10
Private _itemsinmru as Integer = 4

Private _settingschanged as Boolean = False
Private _appversion as String = "1.0"

<categoryattribute ("Document Settings"), _
DefaultValueAttribute (True) > _
Public Property saveOnClose () as Boolean
Get
Return _saveonclose
End Get
Set (ByVal Value as Boolean)
saveOnClose = Value
End Set
End Property

<categoryattribute ("Global Settings"), _
ReadOnlyAttribute (True), _
DefaultValueAttribute ("Welcome to the application!") ") > _
Public Property Greetingtext () as String
Get
Return _greetingtext
End Get
Set (ByVal Value as String)
_greetingtext = Value
End Set
End Property

<categoryattribute ("Global Settings"), _
DefaultValueAttribute (4) > _
Public Property Itemsinmrulist () as Integer
Get
Return _itemsinmru
End Get
Set (ByVal Value as Integer)
_itemsinmru = Value
End Set
End Property

<descriptionattribute ("The text repetition rate in milliseconds.") "), _
CategoryAttribute ("Global Settings"), _
DefaultValueAttribute (A) > _
Public Property maxRepeatRate () as Integer
Get
Return _maxrepeatrate
End Get
Set (ByVal Value as Integer)
_maxrepeatrate = Value
End Set
End Property

<browsableattribute (False),
DefaultValueAttribute (False) > _
Public Property settingschanged () as Boolean
Get
Return _settingschanged
End Get
Set (ByVal Value as Boolean)
_settingschanged = Value
End Set
End Property

<categoryattribute ("Version"), _
DefaultValueAttribute ("1.0"), _
ReadOnlyAttribute (True) > _
Public Property appversion () as String
Get
Return _appversion
End Get
Set (ByVal Value as String)
_appversion = Value
End Set
End Property
End Class




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.