EditorAttribute 类

定义

指定用于更改属性的编辑器。Specifies the editor to use to change a property. 无法继承此类。This class cannot be inherited.

public ref class EditorAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=true, Inherited=true)]
public sealed class EditorAttribute : Attribute
type EditorAttribute = class
    inherit Attribute
Public NotInheritable Class EditorAttribute
Inherits Attribute
继承
EditorAttribute
属性

示例

下面的代码示例创建 MyImage 类。The following code example creates the MyImage class. 类标记有 EditorAttribute,它将 ImageEditor 指定为其编辑器。The class is marked with an EditorAttribute that specifies the ImageEditor as its editor.

[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使用的编辑器的名称。The following code example creates an instance of the MyImage class, gets the attributes for the class, and then prints the name of the editor used by 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 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 = (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

注解

编辑属性时,可视化设计器应通过对话框或下拉窗口创建指定编辑器的新实例。When editing the property, a visual designer should create a new instance of the specified editor through a dialog box or drop-down window.

使用 EditorBaseTypeName 属性可查找此编辑器的基类型。Use the EditorBaseTypeName property to find this editor's base type. 唯一可用的基类型是 UITypeEditorThe only available base type is UITypeEditor.

使用 EditorTypeName 属性可获取与此属性关联的编辑器类型的名称。Use the EditorTypeName property to get the name of the type of editor associated with this attribute.

有关使用属性的一般信息。For general information on using attributes. 请参阅特性see Attributes. 有关设计时特性的详细信息,请参阅特性和设计时支持For more information on design-time attributes, see Attributes and Design-Time Support.

构造函数

EditorAttribute()

用默认的编辑器(即不使用任何编辑器)初始化 EditorAttribute 类的新实例。Initializes a new instance of the EditorAttribute class with the default editor, which is no editor.

EditorAttribute(String, String)

用编辑器的类型名称和基类型名称初始化 EditorAttribute 类的新实例。Initializes a new instance of the EditorAttribute class with the type name and base type name of the editor.

EditorAttribute(String, Type)

用类型名和基类型来初始化 EditorAttribute 类的新实例。Initializes a new instance of the EditorAttribute class with the type name and the base type.

EditorAttribute(Type, Type)

用类型和基类型初始化 EditorAttribute 类的新实例。Initializes a new instance of the EditorAttribute class with the type and the base type.

属性

EditorBaseTypeName

获取作为此编辑器查找键的基类或接口的名称。Gets the name of the base class or interface serving as a lookup key for this editor.

EditorTypeName

获取 AssemblyQualifiedName 格式的编辑器类的名称。Gets the name of the editor class in the AssemblyQualifiedName format.

TypeId

获取此特性类型的唯一 ID。Gets a unique ID for this attribute type.

方法

Equals(Object)

返回给定对象的值是否等于当前的 EditorAttributeReturns whether the value of the given object is equal to the current EditorAttribute.

GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于