CategoryAttribute Classe

Definição

Especifica o nome da categoria em que se deve agrupar a propriedade ou evento quando exibido num PropertyGrid controlo definido em modo Categorizado.

public ref class CategoryAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public class CategoryAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type CategoryAttribute = class
    inherit Attribute
Public Class CategoryAttribute
Inherits Attribute
Herança
CategoryAttribute
Atributos

Exemplos

O exemplo seguinte cria a MyImage propriedade. A propriedade tem dois atributos: a DescriptionAttribute e a 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

O exemplo seguinte obtém a categoria para MyImage. Primeiro, o código recebe a PropertyDescriptorCollection com todas as propriedades do objeto. De seguida, o código indexa-se para obter PropertyDescriptorCollectionMyImage. Depois, devolve os atributos desta propriedade e guarda-os na variável attributes.

O exemplo imprime então a categoria recuperando-a CategoryAttribute do AttributeCollection, e escrevendo-a no ecrã da consola.

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

Observações

A indica a categoria a associar a propriedade ou evento associado, ao listar CategoryAttribute propriedades ou eventos num PropertyGrid controlo definido para Categorized modo. Se a CategoryAttribute não tiver sido aplicado a uma propriedade ou evento, associa-o PropertyGrid à categoria Misc . Pode ser criada uma nova categoria para qualquer nome especificando o nome da categoria no construtor para o CategoryAttribute.

A Category propriedade indica o nome da categoria que o atributo representa. A Category propriedade também proporciona uma localização transparente dos nomes das categorias.

Notas para Herdeiros

Se usar nomes de categorias diferentes dos pré-definidos e quiser localizar os nomes das suas categorias, deve sobrescrever o GetLocalizedString(String) método.

A CategoryAttribute classe define as seguintes categorias comuns:

Categoria Descrição
Action Propriedades relacionadas com ações disponíveis.
Appearance Propriedades relacionadas com a aparência de uma entidade.
Behavior Propriedades relacionadas com o comportamento de uma entidade.
Data Propriedades relacionadas com dados e gestão de fontes de dados.
Default Propriedades agrupadas numa categoria padrão.
Design Propriedades que só estão disponíveis no momento do projeto.
DragDrop Propriedades relacionadas com operações de arrastar e largar.
Focus Propriedades relacionadas com o foco.
Format Propriedades relacionadas com formatação.
Key Propriedades relacionadas com o teclado.
Layout Propriedades relacionadas com o layout.
Mouse Propriedades relacionadas com o rato.
WindowStyle Propriedades relacionadas com o estilo de janela das formas de nível superior.

Para obter mais informações, consulte Atributos.

Construtores

Name Description
CategoryAttribute()

Inicializa uma nova instância da CategoryAttribute classe usando o nome da categoria Default.

CategoryAttribute(String)

Inicializa uma nova instância da CategoryAttribute classe usando o nome da categoria especificado.

Propriedades

Name Description
Action

Recebe um CategoryAttribute que representa a categoria de Ação.

Appearance

Recebe um CategoryAttribute a representar a categoria Aparência.

Asynchronous

Obtém um CategoryAttribute que representa a categoria Assíncrona.

Behavior

Obtém um CategoryAttribute que representa a categoria Comportamento.

Category

Obtém o nome da categoria da propriedade ou evento a que este atributo é aplicado.

Data

Obtém um CategoryAttribute que representa a categoria Dados.

Default

Recebe um CategoryAttribute que representa a categoria Default.

Design

Recebe um CategoryAttribute representante da categoria Design.

DragDrop

Obtém um CategoryAttribute que representa a categoria Arrastar e Largar.

Focus

Recebe um CategoryAttribute que representa a categoria Foco.

Format

Obtém um CategoryAttribute que representa a categoria Format.

Key

Obtém um CategoryAttribute que representa a categoria chave.

Layout

Obtém uma CategoryAttribute que representa a categoria de Disposição.

Mouse

Recebe uma CategoryAttribute categoria que representa o Rato.

TypeId

Quando implementado numa classe derivada, obtém um identificador único para esta Attribute.

(Herdado de Attribute)
WindowStyle

Recebe um CategoryAttribute que representa a categoria WindowStyle.

Métodos

Name Description
Equals(Object)

Devolve se o valor do objeto dado é igual à corrente CategoryAttribute.

GetHashCode()

Devolve o código de hash deste atributo.

GetLocalizedString(String)

Procura o nome localizado da categoria especificada.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Determina se este atributo é o padrão.

Match(Object)

Quando sobrescrito numa classe derivada, devolve um valor que indica se esta instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

Implementações de Interface Explícita

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

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de despacho.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera a informação de tipo de um objeto, que pode ser usada para obter a informação de tipo para uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera o número de interfaces de informações de tipo que um objeto fornece (0 ou 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Proporciona acesso a propriedades e métodos expostos por um objeto.

(Herdado de Attribute)

Aplica-se a

Ver também