DesignerCategoryAttribute Klasa

Definicja

Określa, że projektant klasy należy do określonej kategorii.

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

Przykłady

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

[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design",
IRootDesigner::typeid),
DesignerCategory("Form")]
ref class MyForm: public ContainerControl{
   // Insert code here.
};
[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design", 
    typeof(IRootDesigner)),
    DesignerCategory("Form")]
    
 public class MyForm : ContainerControl {
    // Insert code here.
 }
<Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design", _
    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 DesignerCategoryAttributeelement i wyświetla 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 
       * DesignerCategoryAttribute from the AttributeCollection. */
   DesignerCategoryAttribute^ myAttribute = dynamic_cast<DesignerCategoryAttribute^>(attributes[ DesignerCategoryAttribute::typeid ]);
   Console::WriteLine( "The category of the designer for this class is: {0}", myAttribute->Category );
   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 
     * DesignerCategoryAttribute from the AttributeCollection. */
    DesignerCategoryAttribute myAttribute = 
       (DesignerCategoryAttribute)attributes[typeof(DesignerCategoryAttribute)];
    Console.WriteLine("The category of the designer for this class is: " + myAttribute.Category);
  
    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
    ' DesignerCategoryAttribute from the AttributeCollection. 
    Dim myAttribute As DesignerCategoryAttribute = _
        CType(attributes(GetType(DesignerCategoryAttribute)), DesignerCategoryAttribute)
    Console.WriteLine(("The category of the designer for this class is: " + myAttribute.Category))
    Return 0
End Function 'Main

Uwagi

Projektant wizualny może użyć kategorii projektanta, aby poinformować środowisko deweloperskie o typie projektanta, który zostanie zaimplementowany. Jeśli w klasie nie podano żadnej kategorii projektanta, środowisko deweloperskie może lub nie zezwala na projektowanie klasy. Kategorię można utworzyć dla dowolnej nazwy.

Gdy oznaczysz klasę za pomocą tego atrybutu, zostanie ona ustawiona na stałą składową. Jeśli chcesz sprawdzić wartość tego atrybutu w kodzie, musisz określić stały element członkowski. Kolumna Opis w poniższej tabeli zawiera listę stałych elementów członkowskich, na które jest ustawiona każda wartość.

Klasa DesignerCategoryAttribute definiuje następujące typowe kategorie:

Kategoria Opis
Składnik Projektanci, którzy są używane ze składnikami. Atrybut jest ustawiony na stały element członkowski DesignerCategoryAttribute.Component.
Formularz Projektanci, którzy są używane z formularzami. Atrybut jest ustawiony na stały element członkowski DesignerCategoryAttribute.Form.
Projektant Projektanci, którzy są używane z projektantami. Atrybut jest ustawiony na stały element członkowski DesignerCategoryAttribute.Generic.
Pusty ciąg ("") Jest to kategoria domyślna.

Aby uzyskać więcej informacji, zobacz Atrybuty.

Konstruktory

DesignerCategoryAttribute()

Inicjuje DesignerCategoryAttribute nowe wystąpienie klasy z pustym ciągiem ("").

DesignerCategoryAttribute(String)

Inicjuje nowe wystąpienie DesignerCategoryAttribute klasy o podanej nazwie kategorii.

Pola

Component

Określa, że składnik oznaczony tą kategorią używa projektanta składników. To pole jest tylko do odczytu.

Default

Określa, że składnik oznaczony tą kategorią nie może używać projektanta wizualnego. To static pole jest tylko do odczytu.

Form

Określa, że składnik oznaczony tą kategorią używa projektanta formularzy. To static pole jest tylko do odczytu.

Generic

Określa, że składnik oznaczony tą kategorią używa projektanta ogólnego. To static pole jest tylko do odczytu.

Właściwości

Category

Pobiera nazwę kategorii.

TypeId

Pobiera unikatowy identyfikator tego atrybutu.

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attributeelementu .

(Odziedziczone po Attribute)

Metody

Equals(Object)

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

GetHashCode()

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

GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

Określa, czy ten atrybut jest domyślny.

IsDefaultAttribute()

Podczas zastępowania w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną dla klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

Po przesłonięciu 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 dla obiektu, który może służyć do pobierania informacji o typie dla 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ż