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. 唯一可用的基底類型UITypeEditor是。The 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 的淺層複本 (Shallow Copy)。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)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。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)

適用於