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 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

備註

編輯屬性時,可視化設計工具應該透過對話框或下拉式視窗建立指定編輯器的新實例。

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)

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

適用於