DesignerCategoryAttribute Clase
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Especifica que el diseñador de una clase pertenece a una determinada categoría.
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
- Herencia
- Atributos
Ejemplos
En el ejemplo siguiente se crea una clase denominada MyForm.
MyForm tiene dos atributos, un DesignerAttribute que especifica esta clase usa , DocumentDesignery que DesignerCategoryAttribute especifica la Form categoría .
[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
En el ejemplo siguiente se crea una instancia de MyForm. A continuación, obtiene los atributos de la clase , extrae DesignerCategoryAttributey imprime el nombre del diseñador.
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
Comentarios
Un diseñador visual puede usar una categoría de diseñador para informar a un entorno de desarrollo del tipo de diseñador que se implementará. Si no se proporciona ninguna categoría de diseñador en una clase, un entorno de desarrollo puede o no permitir que se diseñe la clase. Se puede crear una categoría para cualquier nombre.
Al marcar una clase con este atributo, se establece en un miembro constante. Cuando desee comprobar el valor de este atributo en el código, debe especificar el miembro constante. En la columna Descripción de la tabla siguiente se muestra el miembro constante en el que se establece cada valor.
La DesignerCategoryAttribute clase define las siguientes categorías comunes:
| Category | Descripción |
|---|---|
| Componente | Diseñadores que se usan con componentes. El atributo se establece en el miembro DesignerCategoryAttribute.Componentconstante . |
| Form | Diseñadores que se usan con formularios. El atributo se establece en el miembro DesignerCategoryAttribute.Formconstante . |
| Diseñador | Diseñadores que se usan con diseñadores. El atributo se establece en el miembro DesignerCategoryAttribute.Genericconstante . |
| Cadena vacía ("") | Esta es la categoría predeterminada. |
Para obtener más información, consulte Attributes (Atributos).
Constructores
| Nombre | Description |
|---|---|
| DesignerCategoryAttribute() |
Inicializa una nueva instancia de la DesignerCategoryAttribute clase con una cadena vacía (""). |
| DesignerCategoryAttribute(String) |
Inicializa una nueva instancia de la DesignerCategoryAttribute clase con el nombre de categoría especificado. |
Campos
| Nombre | Description |
|---|---|
| Component |
Especifica que un componente marcado con esta categoría usa un diseñador de componentes. Este campo es de sólo lectura. |
| Default |
Especifica que un componente marcado con esta categoría no puede usar un diseñador visual. Este |
| Form |
Especifica que un componente marcado con esta categoría usa un diseñador de formularios. Este |
| Generic |
Especifica que un componente marcado con esta categoría use un diseñador genérico. Este |
Propiedades
| Nombre | Description |
|---|---|
| Category |
Obtiene el nombre de la categoría. |
| TypeId |
Obtiene un identificador único para este atributo. |
Métodos
| Nombre | Description |
|---|---|
| Equals(Object) |
Devuelve si el valor del objeto especificado es igual al actual DesignOnlyAttribute. |
| GetHashCode() |
Devuelve el código hash de esta instancia. |
| GetType() |
Obtiene el Type de la instancia actual. (Heredado de Object) |
| IsDefaultAttribute() |
Determina si este atributo es el valor predeterminado. |
| Match(Object) |
Cuando se reemplaza en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado. (Heredado de Attribute) |
| MemberwiseClone() |
Crea una copia superficial del Objectactual. (Heredado de Object) |
| ToString() |
Devuelve una cadena que representa el objeto actual. (Heredado de Object) |
Implementaciones de interfaz explícitas
| Nombre | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío. (Heredado de Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera la información de tipo de un objeto, que se puede usar para obtener la información de tipo de una interfaz. (Heredado de Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1). (Heredado de Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Proporciona acceso a propiedades y métodos expuestos por un objeto . (Heredado de Attribute) |