DesignerCategoryAttribute Classe

Definição

Especifica que o designer de uma classe pertence a uma determinada categoria.

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

Exemplos

O exemplo a seguir cria uma classe chamada MyForm. MyForm tem dois atributos, um DesignerAttribute que especifica que essa classe usa o DocumentDesignere um DesignerCategoryAttribute que especifica a Form categoria.

[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

O próximo exemplo cria uma instância de MyForm. Em seguida, ele obtém os atributos para a classe , extrai o DesignerCategoryAttributee imprime o nome do designer.

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

Comentários

Um designer visual pode usar uma categoria de designer para informar um ambiente de desenvolvimento do tipo de designer que será implementado. Se nenhuma categoria de designer for fornecida em uma classe, um ambiente de desenvolvimento poderá ou não permitir que a classe seja projetada. Uma categoria pode ser criada para qualquer nome.

Quando você marca uma classe com esse atributo, ela é definida como um membro constante. Quando você quiser marcar o valor desse atributo em seu código, especifique o membro constante. A coluna Descrição na tabela abaixo lista o membro constante para o qual cada valor está definido.

A DesignerCategoryAttribute classe define as seguintes categorias comuns:

Categoria Descrição
Componente Designers usados com componentes. O atributo é definido como o membro DesignerCategoryAttribute.Componentconstante .
Formulário Designers que são usados com formulários. O atributo é definido como o membro DesignerCategoryAttribute.Formconstante .
Designer Designers que são usados com designers. O atributo é definido como o membro DesignerCategoryAttribute.Genericconstante .
Cadeia de caracteres vazia ("") Essa é a categoria padrão.

Para obter mais informações, consulte Atributos.

Construtores

DesignerCategoryAttribute()

Inicializa uma nova instância da classe DesignerCategoryAttribute com uma cadeia de caracteres vazia.

DesignerCategoryAttribute(String)

Inicializa uma nova instância da classe DesignerCategoryAttribute com o nome de categoria fornecido.

Campos

Component

Especifica que um componente marcado com essa categoria use um designer de componente. Este campo é somente leitura.

Default

Especifica que um componente marcado com essa categoria não pode usar um designer de componente. Esse campo static é somente leitura.

Form

Especifica que um componente marcado com essa categoria use um designer de formulários. Esse campo static é somente leitura.

Generic

Especifica que um componente marcado com essa categoria use um designer genérico. Esse campo static é somente leitura.

Propriedades

Category

Obtém o nome da categoria.

TypeId

Obtém um identificador exclusivo para este atributo.

TypeId

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

(Herdado de Attribute)

Métodos

Equals(Object)

Retorna se o valor do objeto especificado é igual ao DesignOnlyAttribute atual.

GetHashCode()

Retorna o código hash para a instância.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Determina se este atributo é o padrão.

IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.

(Herdado de Attribute)
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 Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

_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 para um objeto, que pode ser usado para obter as informações de tipo para 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