共用方式為


EditorAttribute 類別

定義

指定要用來變更屬性的編輯器。 無法繼承這個類別。

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
繼承
EditorAttribute
屬性

範例

以下程式碼範例會建立該 MyImage 類別。 類別被標記為 EditorAttribute ,指定 為 ImageEditor 其編輯器。

[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 支援

建構函式

名稱 Description
EditorAttribute()

初始化一個新的類別實例 EditorAttribute ,使用預設編輯器,該編輯器並非編輯器。

EditorAttribute(String, String)

初始化一個新的類別實例 EditorAttribute ,使用編輯器的型別名稱與基底型別名稱。

EditorAttribute(String, Type)

初始化一個帶有類型名稱和基底型態的 EditorAttribute 類別新實例。

EditorAttribute(Type, Type)

初始化一個新的類別實例 EditorAttribute ,包含 類型與基底類型。

屬性

名稱 Description
EditorBaseTypeName

取得基底類別或介面的名稱,作為此編輯器的查找鍵。

EditorTypeName

格式中會取得編輯器類別 AssemblyQualifiedName 的名稱。

TypeId

會為此屬性類型取得唯一 ID。

方法

名稱 Description
Equals(Object)

回傳給定物件的值是否等於當前 EditorAttribute值。

GetHashCode()

傳回這個實例的哈希碼。

GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

明確介面實作

名稱 Description
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取 物件的型別資訊,可用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開屬性和方法的存取權。

(繼承來源 Attribute)

適用於