Partilhar via


DesignerAttribute Classe

Definição

Especifica a classe usada para implementar serviços de tempo de design para um componente.

public ref class DesignerAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true, Inherited=true)]
public sealed class DesignerAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true, Inherited=true)>]
type DesignerAttribute = class
    inherit Attribute
Public NotInheritable Class DesignerAttribute
Inherits Attribute
Herança
DesignerAttribute
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.DLL",
IRootDesigner::typeid),
DesignerCategory("Form")]
ref class MyForm: public ContainerControl{
   // Insert code here.
};
[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL",
    typeof(IRootDesigner)),
    DesignerCategory("Form")]
public class MyForm : ContainerControl
{
    // Insert code here.
}
<Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL", _
    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 DesignerAttributee 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 DesignerAttribute
       * from the AttributeCollection. */
   DesignerAttribute^ myAttribute = dynamic_cast<DesignerAttribute^>(attributes[ DesignerAttribute::typeid ]);
   Console::WriteLine( "The designer for this class is: {0}", myAttribute->DesignerTypeName );
   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 DesignerAttribute
     * from the AttributeCollection. */
    DesignerAttribute myAttribute =
       (DesignerAttribute)attributes[typeof(DesignerAttribute)];
    Console.WriteLine("The designer for this class is: " + myAttribute.DesignerTypeName);

    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 DesignerAttribute
    ' from the AttributeCollection. 
    Dim myAttribute As DesignerAttribute = _
        CType(attributes(GetType(DesignerAttribute)), DesignerAttribute)
    Console.WriteLine(("The designer for this class is: " & myAttribute.DesignerTypeName))
    
    Return 0
End Function 'Main

Comentários

A classe usada para os serviços de tempo de design deve implementar a IDesigner interface.

Use a DesignerBaseTypeName propriedade para localizar o tipo base do designer. Use a DesignerTypeName propriedade para obter o nome do tipo de designer associado a esse membro.

Para obter mais informações, consulte Atributos.

Construtores

Nome Description
DesignerAttribute(String, String)

Inicializa uma nova instância da DesignerAttribute classe usando o tipo de designer e a classe base para o designer.

DesignerAttribute(String, Type)

Inicializa uma nova instância da DesignerAttribute classe, usando o nome da classe de designer e a classe base para o designer.

DesignerAttribute(String)

Inicializa uma nova instância da DesignerAttribute classe usando o nome do tipo que fornece serviços de tempo de design.

DesignerAttribute(Type, Type)

Inicializa uma nova instância da DesignerAttribute classe usando os tipos do designer e da classe base do designer.

DesignerAttribute(Type)

Inicializa uma nova instância da DesignerAttribute classe usando o tipo que fornece serviços de tempo de design.

Propriedades

Nome Description
DesignerBaseTypeName

Obtém o nome do tipo base desse designer.

DesignerTypeName

Obtém o nome do tipo de designer associado a esse atributo de designer.

TypeId

Obtém uma ID exclusiva para esse tipo de atributo.

Métodos

Nome Description
Equals(Object)

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

GetHashCode()

Retorna o código hash dessa instância.

GetType()

Obtém o Type da instância atual.

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