DesignerAttribute 類別

定義

指定用來實作元件之設計階段服務的類別。Specifies the class used to implement design-time services for a component.

public ref class DesignerAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true, Inherited=true)]
public sealed class DesignerAttribute : Attribute
type DesignerAttribute = class
    inherit Attribute
Public NotInheritable Class DesignerAttribute
Inherits Attribute
繼承
DesignerAttribute
屬性

範例

下列範例會建立名為 MyForm的類別。The following example creates a class called MyForm. MyForm 有兩個屬性,指定此類別的 DesignerAttribute 會使用 DocumentDesigner,以及指定 Form 分類的 DesignerCategoryAttributeMyForm has two attributes, a DesignerAttribute that specifies this class uses the DocumentDesigner, and a DesignerCategoryAttribute that specifies the Form category.

[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL",
IRootDesigner::typeid),
DesignerCategory("Form")]
ref class MyForm: public ContainerControl{
   // Insert code here.
};
[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL", 
    typeof(IRootDesigner)),
    DesignerCategory("Form")]
public class MyForm : ContainerControl {
    // Insert code here.
}
<Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL", _
    GetType(IRootDesigner)), DesignerCategory("Form")> _
Public Class MyForm
    
    Inherits ContainerControl
    ' Insert code here.
End Class

下一個範例會建立 MyForm的實例。The next example creates an instance of MyForm. 然後,它會取得類別的屬性、解壓縮 DesignerAttribute,並列印設計工具的名稱。Then it gets the attributes for the class, extracts the DesignerAttribute, and prints the name of the designer.

int main()
{
   // Creates a new form.
   MyForm^ myNewForm = gcnew 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 = dynamic_cast<DesignerAttribute^>(attributes[ DesignerAttribute::typeid ]);
   Console::WriteLine( "The designer for this class is: {0}", myAttribute->DesignerTypeName );
   return 0;
}
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;
}
Public Shared Function Main() As Integer
    ' Creates a new form.
    Dim myNewForm As New MyForm()
    
    ' Gets the attributes for the collection.
    Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewForm)
    
    ' Prints the name of the designer by retrieving the DesignerAttribute
    ' from the AttributeCollection. 
    Dim myAttribute As DesignerAttribute = _
        CType(attributes(GetType(DesignerAttribute)), DesignerAttribute)
    Console.WriteLine(("The designer for this class is: " & myAttribute.DesignerTypeName))
    
    Return 0
End Function 'Main

備註

您用於設計階段服務的類別必須執行 IDesigner 介面。The class you use for the design-time services must implement the IDesigner interface.

使用 DesignerBaseTypeName 屬性來尋找設計工具的基底類型。Use the DesignerBaseTypeName property to find the designer's base type. 使用 [DesignerTypeName] 屬性,即可取得與這個成員相關聯的設計工具類型名稱。Use the DesignerTypeName property to get the name of the type of designer associated with this member.

如需詳細資訊,請參閱屬性For more information, see Attributes.

建構函式

DesignerAttribute(String)

使用提供設計階段服務的型別名稱來初始化 DesignerAttribute 類別的新執行個體。Initializes a new instance of the DesignerAttribute class using the name of the type that provides design-time services.

DesignerAttribute(String, String)

使用設計工具型別和設計工具的基底類別 (Base Class) 來初始化 DesignerAttribute 類別的新執行個體。Initializes a new instance of the DesignerAttribute class using the designer type and the base class for the designer.

DesignerAttribute(String, Type)

使用設計工具類別的名稱和設計工具的基底類別來初始化 DesignerAttribute 類別的新執行個體。Initializes a new instance of the DesignerAttribute class, using the name of the designer class and the base class for the designer.

DesignerAttribute(Type)

使用提供設計階段服務的型別來初始化 DesignerAttribute 類別的新執行個體。Initializes a new instance of the DesignerAttribute class using the type that provides design-time services.

DesignerAttribute(Type, Type)

使用設計工具的型別和設計工具基底類別來初始化 DesignerAttribute 類別的新執行個體。Initializes a new instance of the DesignerAttribute class using the types of the designer and designer base class.

屬性

DesignerBaseTypeName

取得這個設計工具的基底型別名稱。Gets the name of the base type of this designer.

DesignerTypeName

取得與這個設計工具屬性相關的設計工具型別名稱。Gets the name of the designer type associated with this designer attribute.

TypeId

取得此屬性型別的唯一 ID。Gets a unique ID for this attribute type.

方法

Equals(Object)

傳回值,表示指定的物件值是否等於目前的 DesignerAttributeReturns whether the value of the given object is equal to the current DesignerAttribute.

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 的淺層複製。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)

適用於

另請參閱