DesignerAttribute Klasa

Definicja

Określa klasę używaną do implementowania usług czasu projektowania dla składnika.

public ref class DesignerAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true, Inherited=true)]
public sealed class DesignerAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true, Inherited=true)>]
type DesignerAttribute = class
    inherit Attribute
Public NotInheritable Class DesignerAttribute
Inherits Attribute
Dziedziczenie
DesignerAttribute
Atrybuty

Przykłady

Poniższy przykład tworzy klasę o nazwie MyForm. MyForm ma dwa atrybuty, DesignerAttribute które określają tę klasę DocumentDesigner, i DesignerCategoryAttribute która określa kategorię Form .

[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

W następnym przykładzie zostanie utworzone wystąpienie klasy MyForm. Następnie pobiera atrybuty klasy, wyodrębnia DesignerAttributeelement i drukuje nazwę projektanta.

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

Uwagi

Klasa używana dla usług w czasie projektowania musi implementować IDesigner interfejs.

Użyj właściwości , DesignerBaseTypeName aby znaleźć typ podstawowy projektanta. Użyj właściwości , DesignerTypeName aby uzyskać nazwę typu projektanta skojarzonego z tym elementem członkowskim.

Aby uzyskać więcej informacji, zobacz Atrybuty.

Konstruktory

DesignerAttribute(String)

Inicjuje DesignerAttribute nowe wystąpienie klasy przy użyciu nazwy typu, który udostępnia usługi czasu projektowania.

DesignerAttribute(String, String)

Inicjuje DesignerAttribute nowe wystąpienie klasy przy użyciu typu projektanta i klasy bazowej dla projektanta.

DesignerAttribute(String, Type)

Inicjuje nowe wystąpienie DesignerAttribute klasy przy użyciu nazwy klasy projektanta i klasy bazowej projektanta.

DesignerAttribute(Type)

Inicjuje DesignerAttribute nowe wystąpienie klasy przy użyciu typu, który udostępnia usługi czasu projektowania.

DesignerAttribute(Type, Type)

Inicjuje DesignerAttribute nowe wystąpienie klasy przy użyciu typów klasy bazowej projektanta i projektanta.

Właściwości

DesignerBaseTypeName

Pobiera nazwę podstawowego typu tego projektanta.

DesignerTypeName

Pobiera nazwę typu projektanta skojarzonego z tym atrybutem projektanta.

TypeId

Pobiera unikatowy identyfikator tego typu atrybutu.

Metody

Equals(Object)

Zwraca, czy wartość danego obiektu jest równa bieżącej DesignerAttributewartości .

GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
IsDefaultAttribute()

W przypadku zastąpienia w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

W przypadku zastąpienia w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie obiektu, którego można użyć do pobrania informacji o typie interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy

Zobacz też