Condividi tramite


CategoryAttribute Classe

Definizione

Specifica il nome della categoria in cui raggruppare la proprietà o l'evento quando viene visualizzato in un controllo PropertyGrid impostato su Modalità categorizzata.

public ref class CategoryAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public class CategoryAttribute : Attribute
public class CategoryAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type CategoryAttribute = class
    inherit Attribute
type CategoryAttribute = class
    inherit Attribute
Public Class CategoryAttribute
Inherits Attribute
Ereditarietà
CategoryAttribute
Attributi

Esempio

Nell'esempio seguente viene creata la MyImage proprietà . La proprietà ha due attributi: a DescriptionAttribute e .CategoryAttribute

   [Description("The image associated with the control"),Category("Appearance")]
   System::Drawing::Image^ get()
   {
      // Insert code here.
      return m_Image1;
   }

   void set( System::Drawing::Image^ )
   {
      // Insert code here.
   }
}
[Description("The image associated with the control"), Category("Appearance")]
public Image MyImage
{
    get =>
        // Insert code here.
        image1;
    set
    {
        // Insert code here.
    }
}
<Description("The image associated with the control"), _
    Category("Appearance")> _
Public Property MyImage() As Image
    
    Get
        ' Insert code here.
        Return image1
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

Nell'esempio seguente viene recuperata la categoria per MyImage. Innanzitutto, il codice ottiene un PropertyDescriptorCollection oggetto con tutte le proprietà per l'oggetto . Successivamente, il codice indicizza in PropertyDescriptorCollection per ottenere MyImage. Restituisce quindi gli attributi per questa proprietà e li salva nella variabile attributes.

Nell'esempio viene quindi stampata la categoria recuperando CategoryAttribute da AttributeCollectione scrivendola nella schermata della console.

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyImage" ]->Attributes;

// Prints the description by retrieving the CategoryAttribute.
// from the AttributeCollection.
CategoryAttribute^ myAttribute = static_cast<CategoryAttribute^>(attributes[ CategoryAttribute::typeid ]);
Console::WriteLine( myAttribute->Category );
// Gets the attributes for the property.
AttributeCollection attributes =
   TypeDescriptor.GetProperties(this)["MyImage"].Attributes;

// Prints the description by retrieving the CategoryAttribute.
// from the AttributeCollection.
CategoryAttribute myAttribute =
   (CategoryAttribute)attributes[typeof(CategoryAttribute)];
Console.WriteLine(myAttribute.Category);
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("MyImage").Attributes

' Prints the description by retrieving the CategoryAttribute. 
' from the AttributeCollection.
Dim myAttribute As CategoryAttribute = _
    CType(attributes(GetType(CategoryAttribute)), CategoryAttribute)
    Console.WriteLine(myAttribute.Category)

Commenti

Un CategoryAttribute valore indica la categoria a cui associare la proprietà o l'evento associato, quando si elencano proprietà o eventi in un PropertyGrid controllo impostato su Categorized modalità. Se un oggetto CategoryAttribute non è stato applicato a una proprietà o a un evento, PropertyGrid lo associa alla categoria Misc . È possibile creare una nuova categoria per qualsiasi nome specificando il nome della categoria nel costruttore per .CategoryAttribute

La Category proprietà indica il nome della categoria rappresentata dall'attributo. La Category proprietà fornisce anche la localizzazione trasparente dei nomi di categoria.

Note per gli eredi

Se si usano nomi di categoria diversi dai nomi predefiniti e si desidera localizzare i nomi delle categorie, è necessario eseguire l'override del GetLocalizedString(String) metodo .

La CategoryAttribute classe definisce le categorie comuni seguenti:

Category Descrizione
Action Proprietà correlate alle azioni disponibili.
Appearance Proprietà correlate alla modalità di comparsa di un'entità.
Behavior Proprietà correlate alla modalità di funzionamento di un'entità.
Data Proprietà correlate alla gestione dei dati e dell'origine dati.
Default Proprietà raggruppate in una categoria predefinita.
Design Proprietà disponibili solo in fase di progettazione.
DragDrop Proprietà correlate alle operazioni di trascinamento della selezione.
Focus Proprietà correlate allo stato attivo.
Format Proprietà correlate alla formattazione.
Key Proprietà correlate alla tastiera.
Layout Proprietà correlate al layout.
Mouse Proprietà correlate al mouse.
WindowStyle Proprietà correlate allo stile della finestra dei moduli di primo livello.

Per altre informazioni, vedere Attributi.

Costruttori

Nome Descrizione
CategoryAttribute()

Inizializza una nuova istanza della CategoryAttribute classe utilizzando il nome di categoria Default.

CategoryAttribute(String)

Inizializza una nuova istanza della CategoryAttribute classe utilizzando il nome della categoria specificato.

Proprietà

Nome Descrizione
Action

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Azione.

Appearance

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Aspetto.

Asynchronous

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Asincrona.

Behavior

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Comportamento.

Category

Ottiene il nome della categoria per la proprietà o l'evento a cui viene applicato questo attributo.

Data

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Dati.

Default

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Default.

Design

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Progettazione.

DragDrop

Ottiene un oggetto CategoryAttribute che rappresenta la categoria DragDrop.

Focus

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Focus.

Format

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Format.

Key

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Chiave.

Layout

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Layout.

Mouse

Ottiene un oggetto CategoryAttribute che rappresenta la categoria Mouse.

TypeId

Se implementato in una classe derivata, ottiene un identificatore univoco per questo Attribute.

(Ereditato da Attribute)
WindowStyle

Ottiene un oggetto CategoryAttribute che rappresenta la categoria WindowStyle.

Metodi

Nome Descrizione
Equals(Object)

Restituisce un valore che indica se il valore dell'oggetto specificato è uguale all'oggetto corrente CategoryAttribute.

GetHashCode()

Restituisce il codice hash per questo attributo.

GetLocalizedString(String)

Cerca il nome localizzato della categoria specificata.

GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

Determina se questo attributo è l'impostazione predefinita.

Match(Object)

Quando sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

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

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo per un oggetto, che può essere utilizzato per ottenere le informazioni sul tipo per un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso alle proprietà e ai metodi esposti da un oggetto .

(Ereditato da Attribute)

Si applica a

Vedi anche