共用方式為


Attributes in Windows Forms Controls

The .NET Framework provides a variety of attributes you can apply to the members of your custom controls and components. Some of these attributes affect the run-time behavior of a class, and others affect the design-time behavior.

Attributes for Control and Component Properties

The following table shows the attributes you can apply to properties or other members of your custom controls and components. For an example that uses many of these attributes, see How to: Apply Attributes in Windows Forms Controls.

Attribute Description

AmbientValueAttribute

Specifies the value to pass to a property to cause the property to get its value from another source. This is known as ambience.

BrowsableAttribute

Specifies whether a property or event should be displayed in a Properties window.

CategoryAttribute

Specifies the name of the category in which to group the property or event when displayed in a PropertyGrid control set to Categorized mode.

DefaultValueAttribute

Specifies the default value for a property.

DescriptionAttribute

Specifies a description for a property or event.

DisplayNameAttribute

Specifies the display name for a property, event, or public void method that takes no arguments.

EditorAttribute

Specifies the editor to use to change a property.

EditorBrowsableAttribute

Specifies that a property or method is viewable in an editor.

HelpKeywordAttribute

Specifies the context keyword for a class or member.

LocalizableAttribute

Specifies whether a property should be localized.

PasswordPropertyTextAttribute

Indicates that an object's text representation is obscured by characters such as asterisks.

ReadOnlyAttribute

Specifies whether the property this attribute is bound to is read-only or read/write at design time.

RefreshPropertiesAttribute

Indicates that the property grid should refresh when the associated property value changes.

TypeConverterAttribute

Specifies what type to use as a converter for the object this attribute is bound to.

Attributes for Data Binding Properties

The following table shows the attributes you can apply to specify how your custom controls and components interact with data binding.

Attribute Description

BindableAttribute

Specifies whether a property is typically used for binding.

ComplexBindingPropertiesAttribute

Specifies the data source and data member properties for a component.

DefaultBindingPropertyAttribute

Specifies the default binding property for a component.

LookupBindingPropertiesAttribute

Specifies the data source and data member properties for a component.

AttributeProviderAttribute

Enables attribute redirection.

Attributes for Classes

The following table shows the attributes you can apply to specify the behavior of your custom controls and components at design time.


Attribute Description

DefaultEventAttribute

Specifies the default event for a component.

DefaultPropertyAttribute

Specifies the default property for a component.

DesignerAttribute

Specifies the class used to implement design-time services for a component.

DesignerCategoryAttribute

Specifies that the designer for a class belongs to a certain category.

ToolboxItemAttribute

Represents an attribute of a toolbox item.

ToolboxItemFilterAttribute

Specifies the filter string and filter type to use for a Toolbox item.

See Also

Tasks

How to: Apply Attributes in Windows Forms Controls

Reference

Attribute

Other Resources

Extending Design-Time Support
Developing Custom Windows Forms Controls with the .NET Framework