DesignerCategoryAttribute Třída

Definice

Určuje, že návrhář třídy patří do určité kategorie.

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
Dědičnost
DesignerCategoryAttribute
Atributy

Příklady

Následující příklad vytvoří třídu s názvem MyForm. MyForm má dva atributy, DesignerAttribute který určuje tuto třídu používá DocumentDesignera DesignerCategoryAttribute která určuje Form kategorii.

[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

Další příklad vytvoří instanci MyForm. Potom získá atributy pro třídu, extrahuje DesignerCategoryAttributea vytiskne název návrháře.

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();

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

Poznámky

Vizuální návrhář může pomocí kategorie návrháře informovat vývojové prostředí o typu návrháře, který bude implementován. Pokud není ve třídě k dispozici žádná kategorie návrháře, vývojové prostředí může nebo nemusí umožňovat, aby byla třída navržena. Kategorii je možné vytvořit pro libovolný název.

Když označíte třídu tímto atributem, nastaví se na konstantní člen. Pokud chcete zkontrolovat hodnotu tohoto atributu v kódu, musíte zadat konstantní člen. Sloupec Popis v tabulce níže uvádí konstantní člen, na který je každá hodnota nastavená.

Třída DesignerCategoryAttribute definuje následující společné kategorie:

Kategorie Description
Component Návrháři, kteří se používají se součástmi. Atribut je nastaven na konstantní člen DesignerCategoryAttribute.Component.
Form Návrháři, kteří se používají s formuláři. Atribut je nastaven na konstantní člen DesignerCategoryAttribute.Form.
Návrhář Návrháři, kteří se používají s návrháři. Atribut je nastaven na konstantní člen DesignerCategoryAttribute.Generic.
Prázdný řetězec ("") Toto je výchozí kategorie.

Další informace naleznete v tématu Atributy.

Konstruktory

Name Description
DesignerCategoryAttribute()

Inicializuje novou instanci DesignerCategoryAttribute třídy s prázdným řetězcem ("").

DesignerCategoryAttribute(String)

Inicializuje novou instanci DesignerCategoryAttribute třídy s daným názvem kategorie.

Pole

Name Description
Component

Určuje, že komponenta označená touto kategorií používá návrháře komponent. Toto pole je určeno pouze ke čtení.

Default

Určuje, že komponenta označená touto kategorií nemůže použít vizuální návrhář. Toto static pole je jen pro čtení.

Form

Určuje, že součást označená touto kategorií používá návrháře formulářů. Toto static pole je jen pro čtení.

Generic

Určuje, že součást označená touto kategorií používá obecný návrhář. Toto static pole je jen pro čtení.

Vlastnosti

Name Description
Category

Získá název kategorie.

TypeId

Získá jedinečný identifikátor pro tento atribut.

Metody

Name Description
Equals(Object)

Vrátí, zda hodnota daného objektu je rovna aktuální DesignOnlyAttribute.

GetHashCode()

Vrátí kód hash pro tuto instanci.

GetType()

Získá Type aktuální instance.

(Zděděno od Object)
IsDefaultAttribute()

Určuje, zda je tento atribut výchozí.

Match(Object)

Při přepsání v odvozené třídě vrátí hodnotu, která určuje, zda se tato instance rovná zadanému objektu.

(Zděděno od Attribute)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

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

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Načte informace o typu objektu, který lze použít k získání informací o typu pro rozhraní.

(Zděděno od Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od Attribute)

Platí pro

Viz také