Compartilhar via


CategoryAttribute Classe

Definição

Especifica o nome da categoria na qual agrupar a propriedade ou evento quando exibido em um controle PropertyGrid definido como modo Categorizado.

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
Herança
CategoryAttribute
Atributos

Exemplos

O exemplo a seguir cria a MyImage propriedade. A propriedade tem dois atributos: a DescriptionAttribute e um 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 próximo exemplo obtém a categoria para MyImage. Primeiro, o código obtém uma PropertyDescriptorCollection com todas as propriedades do objeto. Em seguida, o código indexa no PropertyDescriptorCollection para obter MyImage. Em seguida, retorna os atributos dessa propriedade e os salva na variável attributes.

Em seguida, o exemplo imprime a categoria recuperando-a AttributeCollectione gravando-a CategoryAttribute na tela do 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)

Comentários

Um CategoryAttribute indica a categoria à qual associar a propriedade ou evento associado, ao listar propriedades ou eventos em um PropertyGrid controle definido como Categorized modo. Se um CategoryAttribute não tiver sido aplicado a uma propriedade ou evento, o PropertyGrid associará à categoria Misc . Uma nova categoria pode ser criada 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 fornece localização transparente de nomes de categoria.

Notas aos Herdeiros

Se você usar nomes de categoria diferentes dos nomes predefinidos e quiser localizar seus nomes de categoria, deverá substituir o GetLocalizedString(String) método.

A CategoryAttribute classe define as seguintes categorias comuns:

Category Descrição
Action Propriedades relacionadas a ações disponíveis.
Appearance Propriedades relacionadas à forma como uma entidade é exibida.
Behavior Propriedades relacionadas a como uma entidade age.
Data Propriedades relacionadas ao gerenciamento de dados e fontes de dados.
Default Propriedades agrupadas em uma categoria padrão.
Design Propriedades disponíveis somente no momento do design.
DragDrop Propriedades relacionadas a operações de arrastar e soltar.
Focus Propriedades relacionadas ao foco.
Format Propriedades relacionadas à formatação.
Key Propriedades relacionadas ao teclado.
Layout Propriedades relacionadas ao layout.
Mouse Propriedades relacionadas ao mouse.
WindowStyle Propriedades relacionadas ao estilo de janela de formulários de nível superior.

Para obter mais informações, consulte Atributos.

Construtores

Nome Description
CategoryAttribute()

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

CategoryAttribute(String)

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

Propriedades

Nome Description
Action

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

Appearance

Obtém uma CategoryAttribute categoria que representa a aparência.

Asynchronous

Obtém uma CategoryAttribute categoria assíncrona que representa.

Behavior

Obtém uma CategoryAttribute categoria de comportamento que representa.

Category

Obtém o nome da categoria para a propriedade ou evento ao qual esse atributo é aplicado.

Data

Obtém uma CategoryAttribute categoria de dados que representa.

Default

Obtém uma CategoryAttribute categoria que representa a categoria Padrão.

Design

Obtém uma CategoryAttribute categoria que representa o Design.

DragDrop

Obtém uma CategoryAttribute representação da categoria DragDrop.

Focus

Obtém uma CategoryAttribute categoria que representa o Foco.

Format

Obtém uma CategoryAttribute categoria que representa o formato.

Key

Obtém uma CategoryAttribute categoria de chave que representa.

Layout

Obtém uma CategoryAttribute categoria que representa o Layout.

Mouse

Obtém uma CategoryAttribute categoria que representa o Mouse.

TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para esse Attribute.

(Herdado de Attribute)
WindowStyle

Obtém uma CategoryAttribute representação da categoria WindowStyle.

Métodos

Nome Description
Equals(Object)

Retorna se o valor do objeto fornecido é igual ao atual CategoryAttribute.

GetHashCode()

Retorna o código hash desse atributo.

GetLocalizedString(String)

Pesquisa o nome localizado da categoria especificada.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Determina se esse atributo é o padrão.

Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Objectatual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

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

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.

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

Recupera as informações de tipo de um objeto, que podem ser usadas para obter as informações de tipo de uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

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

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

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

(Herdado de Attribute)

Aplica-se a

Confira também