Specifies a description for a property or event.
For a list of all members of this type, see DescriptionAttribute Members.
System.Object
System.Attribute
System.ComponentModel.DescriptionAttribute
Derived classes
[Visual Basic] <AttributeUsage(AttributeTargets.All)> Public Class DescriptionAttribute Inherits Attribute [C#] [AttributeUsage(AttributeTargets.All)] public class DescriptionAttribute : Attribute [C++] [AttributeUsage(AttributeTargets::All)] public __gc class DescriptionAttribute : public Attribute [JScript] public AttributeUsage(AttributeTargets.All) class DescriptionAttribute extends Attribute
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
A visual designer can display the specified description when referencing the component member, such as in a Properties window. Call Description to access the value of this attribute.
For more information, see
[Visual Basic, C#] The following example creates the MyImage property. The property has two attributes, a DescriptionAttribute and a CategoryAttribute.
[Visual Basic] <Description("The image associated with the control"), _ Category("Appearance")> _ Public Property MyImage() As Image Get ' Insert code here. Return image1 End Get Set ' Insert code here. End Set End Property [C#] [Description("The image associated with the control"),Category("Appearance")] public Image MyImage { get { // Insert code here. return image1; } set { // Insert code here. } }
[Visual Basic, C#] The next example gets the description of MyImage. First the code gets a PropertyDescriptorCollection with all the properties for the object. Next it indexes into the PropertyDescriptorCollection to get MyImage. Then it returns the attributes for this property and saves them in the attributes variable.
[Visual Basic, C#] The example then prints the description by retrieving DescriptionAttribute from the AttributeCollection, and writing it to the console screen.
[Visual Basic] ' Gets the attributes for the property. Dim attributes As AttributeCollection = _ TypeDescriptor.GetProperties(Me)("MyImage").Attributes ' Prints the description by retrieving the DescriptionAttribute ' from the AttributeCollection. Dim myAttribute As DescriptionAttribute = _ CType(attributes(GetType(DescriptionAttribute)), DescriptionAttribute) Console.WriteLine(myAttribute.Description) [C#] // Gets the attributes for the property. AttributeCollection attributes = TypeDescriptor.GetProperties(this)["MyImage"].Attributes; /* Prints the description by retrieving the DescriptionAttribute * from the AttributeCollection. */ DescriptionAttribute myAttribute = (DescriptionAttribute)attributes[typeof(DescriptionAttribute)]; Console.WriteLine(myAttribute.Description);
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Namespace: System.ComponentModel
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)
DescriptionAttribute Members | System.ComponentModel Namespace | Attribute | PropertyDescriptor | EventDescriptor