DescriptionAttribute Class
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
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
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 Attributes Overview and Extending Metadata Using Attributes.
Example
[Visual Basic, C#, 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. } } [C++] public: [Description(S"The image associated with the control"),Category(S"Appearance")] __property Image* get_MyImage() { // Insert code here. return image1; } __property void set_MyImage( Image* value ) { // Insert code here. }
[Visual Basic, C#, 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#, 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++] // Gets the attributes for the property. AttributeCollection* attributes = TypeDescriptor::GetProperties(this)->Item[S"MyImage"]->Attributes; /* Prints the description by retrieving the DescriptionAttribute * from the AttributeCollection. */ DescriptionAttribute* myAttribute = dynamic_cast<DescriptionAttribute*>(attributes->Item[__typeof(DescriptionAttribute)]); Console::WriteLine(myAttribute->Description);
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
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)
See Also
DescriptionAttribute Members | System.ComponentModel Namespace | Attribute | PropertyDescriptor | EventDescriptor