DesignerAttribute 類別

定義

指定用來實作元件之設計階段服務的類別。

C#
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true, Inherited=true)]
public sealed class DesignerAttribute : Attribute
繼承
DesignerAttribute
屬性

範例

下列範例會建立名為的 MyForm類別。 MyForm 有兩個 DesignerAttribute 屬性,指定這個類別使用 DocumentDesigner,以及 DesignerCategoryAttribute 指定類別的 Form

C#
[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL", 
    typeof(IRootDesigner)),
    DesignerCategory("Form")]
public class MyForm : ContainerControl {
    // Insert code here.
}

下一個範例會建立的 MyForm實例。 然後,它會取得 類別的屬性、擷取 DesignerAttribute,並列印設計工具的名稱。

C#
public static int Main() {
    // Creates a new form.
    MyForm myNewForm = new MyForm();
 
    // Gets the attributes for the collection.
    AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewForm);
 
    /* Prints the name of the designer by retrieving the DesignerAttribute
     * from the AttributeCollection. */
    DesignerAttribute myAttribute = 
       (DesignerAttribute)attributes[typeof(DesignerAttribute)];
    Console.WriteLine("The designer for this class is: " + myAttribute.DesignerTypeName);
  
    return 0;
}

備註

您用於設計時間服務的類別必須實 IDesigner 作 介面。

DesignerBaseTypeName使用屬性來尋找設計工具的基底類型。 DesignerTypeName使用屬性來取得與此成員相關聯的設計工具類型名稱。

如需詳細資訊,請參閱屬性

建構函式

DesignerAttribute(String)

使用提供設計階段服務的型別名稱來初始化 DesignerAttribute 類別的新執行個體。

DesignerAttribute(String, String)

使用設計工具型別和設計工具的基底類別 (Base Class) 來初始化 DesignerAttribute 類別的新執行個體。

DesignerAttribute(String, Type)

使用設計工具類別的名稱和設計工具的基底類別來初始化 DesignerAttribute 類別的新執行個體。

DesignerAttribute(Type)

使用提供設計階段服務的型別來初始化 DesignerAttribute 類別的新執行個體。

DesignerAttribute(Type, Type)

使用設計工具的型別和設計工具基底類別來初始化 DesignerAttribute 類別的新執行個體。

屬性

DesignerBaseTypeName

取得這個設計工具的基底型別名稱。

DesignerTypeName

取得與這個設計工具屬性相關的設計工具型別名稱。

TypeId

取得此屬性型別的唯一 ID。

方法

Equals(Object)

傳回值,表示指定的物件值是否等於目前的 DesignerAttribute

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)

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

另請參閱