EditorAttribute 类

指定用来更改属性的编辑器。无法继承此类。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.All, AllowMultiple:=True, Inherited:=True)> _
Public NotInheritable Class EditorAttribute
    Inherits Attribute
用法
Dim instance As EditorAttribute
[AttributeUsageAttribute(AttributeTargets.All, AllowMultiple=true, Inherited=true)] 
public sealed class EditorAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::All, AllowMultiple=true, Inherited=true)] 
public ref class EditorAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.All, AllowMultiple=true, Inherited=true) */ 
public final class EditorAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.All, AllowMultiple=true, Inherited=true) 
public final class EditorAttribute extends Attribute

备注

当编辑属性时,可视化设计器应该通过对话框或下拉窗口来创建指定编辑器的新实例。

使用 EditorBaseTypeName 属性来查找该编辑器的基类型。唯一可用的基类型为 UITypeEditor

使用 EditorTypeName 属性 (Property) 获取与该属性 (Attribute) 关联的编辑器的类型名称。

有关使用属性的常规信息,请参见 属性 (Attribute) 概述利用属性扩展元数据。有关设计时属性的更多信息,请参见 属性与设计时支持

示例

下面的代码示例创建 MyImage 类。该类标有 EditorAttribute,它将 ImageEditor 指定为其编辑器。

<Editor("System.Windows.Forms.ImageEditorIndex, System.Design", _
    GetType(UITypeEditor))> _
Public Class MyImage
    ' Insert code here.
End Class 'MyImage
[Editor("System.Windows.Forms.ImageEditorIndex, System.Design", 
    typeof(UITypeEditor))]

public class MyImage
{
    // Insert code here.
 }
[Editor("System.Windows.Forms.ImageEditorIndex, System.Design",
UITypeEditor::typeid)]
public ref class MyImage{
   // Insert code here.
};
/** @attribute Editor("System.Windows.Forms.ImageEditorIndex, " 
     + "System.Design", UITypeEditor.class)
 */
public static class MyImage
{
    // Insert code here.
} //MyImage

下面的代码示例创建 MyImage 类的一个实例,获取该类的属性,然后输出 myNewImage 所用编辑器的名称。

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 'Main
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;
 }
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 void main(String[] args)
{
    // 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.get_Item(EditorAttribute.class.ToType()));

    Console.WriteLine("The editor for this class is: " 
        + myAttribute.get_EditorTypeName());
} //main

继承层次结构

System.Object
   System.Attribute
    System.ComponentModel.EditorAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

EditorAttribute 成员
System.ComponentModel 命名空间