DesignerCategoryAttribute Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
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 seguinte cria uma classe chamada MyForm.
MyForm tem dois atributos, a DesignerAttribute que especifica esta classe usa o DocumentDesigner, e a 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 seguinte cria uma instância de MyForm. Depois obtém os atributos da classe, extrai o DesignerCategoryAttribute, e 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
Observações
Um designer visual pode usar uma categoria de designer para informar um ambiente de desenvolvimento sobre o tipo de designer que será implementado. Se não for fornecida nenhuma categoria de designer numa classe, um ambiente de desenvolvimento pode ou não permitir que a classe seja desenhada. Pode ser criada uma categoria para qualquer nome.
Quando marca uma classe com este atributo, ela é definida como um membro constante. Quando quiser verificar o valor deste atributo no seu código, deve especificar o membro constante. A coluna Descrição na tabela abaixo lista o elemento constante a que cada valor está definido.
A DesignerCategoryAttribute classe define as seguintes categorias comuns:
| Category | Descrição |
|---|---|
| Componente | Designers que são usados com componentes. O atributo é definido para o elemento DesignerCategoryAttribute.Componentconstante . |
| Form | Designers que são usados com formulários. O atributo é definido para o elemento DesignerCategoryAttribute.Formconstante . |
| Estruturador | Designers que são usados com designers. O atributo é definido para o elemento DesignerCategoryAttribute.Genericconstante . |
| Corda vazia ("") | Esta é a categoria padrão. |
Para obter mais informações, consulte Atributos.
Construtores
| Name | Description |
|---|---|
| DesignerCategoryAttribute() |
Inicializa uma nova instância da DesignerCategoryAttribute classe com uma string vazia (""). |
| DesignerCategoryAttribute(String) |
Inicializa uma nova instância da DesignerCategoryAttribute classe com o nome da categoria dada. |
Campos
| Name | Description |
|---|---|
| Component |
Especifica que um componente marcado com esta categoria utilize um designer de componentes. Este campo é só de leitura. |
| Default |
Especifica que um componente marcado com esta categoria não pode usar um designer visual. Este |
| Form |
Especifica que um componente marcado com esta categoria utiliza um designer de formulários. Este |
| Generic |
Especifica que um componente marcado com esta categoria utilize um designer genérico. Este |
Propriedades
| Name | Description |
|---|---|
| Category |
Recebe o nome da categoria. |
| TypeId |
Obtém um identificador único para este atributo. |
Métodos
| Name | Description |
|---|---|
| Equals(Object) |
Devolve se o valor do objeto dado é igual à corrente DesignOnlyAttribute. |
| GetHashCode() |
Devolve o código de hash para esta instância. |
| 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) |