System.ComponentModel Names ...


.NET Framework Class Library
DisplayNameAttribute Class

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

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)
Syntax

Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Method Or AttributeTargets.Property Or AttributeTargets.Event)> _
Public Class DisplayNameAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As DisplayNameAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Event)]
public class DisplayNameAttribute : Attribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Method|AttributeTargets::Property|AttributeTargets::Event)]
public ref class DisplayNameAttribute : public Attribute
JScript
public class DisplayNameAttribute extends Attribute
Remarks

The default is the name of the property or event. The default implementation of GetSortedActionItems uses reflection to search the public properties and public void methods that take no arguments. GetSortedActionItems searches for the DisplayNameAttribute on each property and method and, if found, uses that string instead of the property or method name.

Examples

The following code example demonstrates using the DisplayNameAttribute class to change the name of a property called MisnamedProperty to RenamedProperty in a PropertyGrid control. For a full code listing, see How to: Apply Attributes in Windows Forms Controls.

Visual Basic
' This property exists only to demonstrate the 
' DisplayName attribute. When this control 
' is attached to a PropertyGrid control, the
' property will be appear as "RenamedProperty"
' instead of "MisnamedProperty".
<Description("Demonstrates DisplayNameAttribute."), _
DisplayName("RenamedProperty")> _
Public ReadOnly Property MisnamedProperty() As Boolean
    Get
        Return True
    End Get
End Property
C#
// This property exists only to demonstrate the 
// DisplayName attribute. When this control 
// is attached to a PropertyGrid control, the
// property will be appear as "RenamedProperty"
// instead of "MisnamedProperty".
[Description("Demonstrates DisplayNameAttribute.")]
[DisplayName("RenamedProperty")]
public bool MisnamedProperty
{
    get
    {
        return true;
    }
}
Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    System.ComponentModel..::.DisplayNameAttribute
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.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0
See Also

Reference

Tags :


Page view tracker