DisplayNameAttribute 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定属性、事件或不采用任何参数的公共 void 方法的显示名称。
public ref class DisplayNameAttribute : Attribute[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Event | System.AttributeTargets.Method | System.AttributeTargets.Property)]
public class DisplayNameAttribute : Attributepublic class DisplayNameAttribute : Attribute[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Event | System.AttributeTargets.Method | System.AttributeTargets.Property)>]
type DisplayNameAttribute = class
    inherit Attributetype DisplayNameAttribute = class
    inherit AttributePublic Class DisplayNameAttribute
Inherits Attribute- 继承
- 属性
示例
下面的代码示例演示如何使用 DisplayNameAttribute 类在 控件中PropertyGrid将名为 MisnamedPropertyRenamedProperty 的属性的名称更改为 。 有关完整代码列表,请参阅如何:在Windows 窗体控件中应用属性。
// This property exists only to demonstrate the 
// DisplayName attribute. When this control 
// is attached to a PropertyGrid control, the
// property will appear as "RenamedProperty"
// instead of "MisnamedProperty".
[Description("Demonstrates DisplayNameAttribute.")]
[DisplayName("RenamedProperty")]
public bool MisnamedProperty
{
    get
    {
        return true;
    }
}
' 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
注解
默认值为属性或事件的名称。 的默认实现 GetSortedActionItems 使用反射来搜索不带参数的公共属性和公共 void 方法。 GetSortedActionItems 在每个属性和方法上搜索 DisplayNameAttribute ,如果找到,则使用该字符串而不是属性或方法名称。
构造函数
| DisplayNameAttribute() | 初始化 DisplayNameAttribute 类的新实例。 | 
| DisplayNameAttribute(String) | 使用显示名称初始化 DisplayNameAttribute 类的新实例。 | 
字段
| Default | 指定 DisplayNameAttribute 的默认值。 此字段为只读。 | 
属性
| DisplayName | 获取属性、事件或不采用此特性中存储的任何参数的公共 void 方法的显示名称。 | 
| DisplayNameValue | 获取或设置显示名称。 | 
| TypeId | 在派生类中实现时,获取此 Attribute 的唯一标识符。(继承自 Attribute) | 
方法
| Equals(Object) | 确定两个 DisplayNameAttribute 实例是否相等。 | 
| GetHashCode() | 返回此实例的哈希代码。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| IsDefaultAttribute() | 确定此特性是否为默认特性。 | 
| IsDefaultAttribute() | 在派生类中重写时,指示此实例的值是否是派生类的默认值。(继承自 Attribute) | 
| Match(Object) | 当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。(继承自 Attribute) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) | 
显式接口实现
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) | 将一组名称映射为对应的一组调度标识符。(继承自 Attribute) | 
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | 检索对象的类型信息,然后可以使用该信息获取接口的类型信息。(继承自 Attribute) | 
| _Attribute.GetTypeInfoCount(UInt32) | 检索对象提供的类型信息接口的数量(0 或 1)。(继承自 Attribute) | 
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | 提供对某一对象公开的属性和方法的访问。(继承自 Attribute) |