DesignerCategoryAttribute Classe
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
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
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)>]
type DesignerCategoryAttribute = class
inherit Attribute
Public NotInheritable Class DesignerCategoryAttribute
Inherits Attribute
- Herança
- 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 exemplo a seguir cria uma instância de MyForm. Em seguida, obtém os atributos da 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();
// 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 verificar o valor desse atributo em seu código, deverá especificar 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 | Description |
|---|---|
| Componente | Designers usados com componentes. O atributo é definido como o membro DesignerCategoryAttribute.Componentconstante. |
| Form | 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
| Nome | Description |
|---|---|
| DesignerCategoryAttribute() |
Inicializa uma nova instância da DesignerCategoryAttribute classe com uma cadeia de caracteres vazia (""). |
| DesignerCategoryAttribute(String) |
Inicializa uma nova instância da DesignerCategoryAttribute classe com o nome da categoria fornecido. |
Campos
| Nome | Description |
|---|---|
| Component |
Especifica que um componente marcado com essa categoria use um designer de componentes. O campo é somente leitura. |
| Default |
Especifica que um componente marcado com essa categoria não pode usar um designer visual. Este |
| Form |
Especifica que um componente marcado com essa categoria use um designer de formulário. Este |
| Generic |
Especifica que um componente marcado com essa categoria use um designer genérico. Este |
Propriedades
| Nome | Description |
|---|---|
| Category |
Obtém o nome da categoria. |
| TypeId |
Obtém um identificador exclusivo para esse atributo. |
Métodos
| Nome | Description |
|---|---|
| Equals(Object) |
Retorna se o valor do objeto fornecido é igual ao atual DesignOnlyAttribute. |
| GetHashCode() |
Retorna o código hash dessa instância. |
| 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) |