EditorAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定要用于更改属性的编辑器。 无法继承此类。
public ref class EditorAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=true, Inherited=true)]
public sealed class EditorAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=true, Inherited=true)>]
type EditorAttribute = class
inherit Attribute
Public NotInheritable Class EditorAttribute
Inherits Attribute
- 继承
- 属性
示例
下面的代码示例创建类 MyImage 。 该类被标记为指定为其编辑器的类EditorAttributeImageEditor。
[Editor("System.Windows.Forms.ImageEditorIndex, System.Design",
UITypeEditor::typeid)]
public ref class MyImage{
// Insert code here.
};
[Editor("System.Windows.Forms.ImageEditorIndex, System.Design",
typeof(UITypeEditor))]
public class MyImage
{
// Insert code here.
}
<Editor("System.Windows.Forms.ImageEditorIndex, System.Design", _
GetType(UITypeEditor))> _
Public Class MyImage
' Insert code here.
End Class
下面的代码示例创建类的 MyImage 实例,获取类的属性,然后打印由该 myNewImage类使用的编辑器的名称。
int main()
{
// Creates a new component.
MyImage^ myNewImage = gcnew MyImage;
// Gets the attributes for the component.
AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewImage );
/* Prints the name of the editor by retrieving the EditorAttribute
* from the AttributeCollection. */
EditorAttribute^ myAttribute = dynamic_cast<EditorAttribute^>(attributes[ EditorAttribute::typeid ]);
Console::WriteLine( "The editor for this class is: {0}", myAttribute->EditorTypeName );
return 0;
}
public static int Main()
{
// Creates a new component.
MyImage myNewImage = new();
// Gets the attributes for the component.
AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewImage);
/* Prints the name of the editor by retrieving the EditorAttribute
* from the AttributeCollection. */
EditorAttribute myAttribute = (EditorAttribute)attributes[typeof(EditorAttribute)];
Console.WriteLine("The editor for this class is: " + myAttribute.EditorTypeName);
return 0;
}
Public Shared Sub Main()
' Creates a new component.
Dim myNewImage As New MyImage()
' Gets the attributes for the component.
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewImage)
' Prints the name of the editor by retrieving the EditorAttribute
' from the AttributeCollection.
Dim myAttribute As EditorAttribute = CType(attributes(GetType(EditorAttribute)), EditorAttribute)
Console.WriteLine(("The editor for this class is: " & myAttribute.EditorTypeName))
End Sub
注解
编辑属性时,视觉设计器应通过对话框或下拉列表窗口创建指定编辑器的新实例。
使用 EditorBaseTypeName 属性查找此编辑器的基类型。 唯一可用的基类型是 UITypeEditor。
使用该 EditorTypeName 属性获取与此特性关联的编辑器类型的名称。
有关使用特性的一般信息。 请参阅 属性。 有关设计时属性的详细信息,请参阅 属性和 Design-Time 支持。
构造函数
| 名称 | 说明 |
|---|---|
| EditorAttribute() |
使用默认编辑器(不是编辑器)初始化类的新实例 EditorAttribute 。 |
| EditorAttribute(String, String) |
使用编辑器的类型名称和基类型名称初始化类的新实例 EditorAttribute 。 |
| EditorAttribute(String, Type) |
使用类型名称和基类型初始化类的新实例 EditorAttribute 。 |
| EditorAttribute(Type, Type) |
使用类型和基类型初始化类的新实例 EditorAttribute 。 |
属性
| 名称 | 说明 |
|---|---|
| EditorBaseTypeName |
获取用作此编辑器查找键的基类或接口的名称。 |
| EditorTypeName |
获取格式的编辑器类 AssemblyQualifiedName 的名称。 |
| TypeId |
获取此属性类型的唯一 ID。 |
方法
| 名称 | 说明 |
|---|---|
| Equals(Object) |
返回给定对象的值是否等于当前 EditorAttribute对象。 |
| GetHashCode() |
返回此实例的哈希代码。 |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| 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) |