DesignerCategoryAttribute Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Specifica che la finestra di progettazione per una classe appartiene a una determinata 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
- Ereditarietà
- Attributi
Esempio
Nell'esempio seguente viene creata una classe denominata MyForm.
MyForm dispone di due attributi, un DesignerAttribute oggetto che specifica questa classe usa e DocumentDesignerun DesignerCategoryAttribute oggetto che specifica la 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
Nell'esempio seguente viene creata un'istanza di MyForm. Ottiene quindi gli attributi per la classe , estrae DesignerCategoryAttributee stampa il nome della finestra di progettazione.
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
Commenti
Una finestra di progettazione visiva può usare una categoria di progettazione per informare un ambiente di sviluppo del tipo di finestra di progettazione che verrà implementato. Se non viene specificata alcuna categoria di progettazione in una classe, un ambiente di sviluppo può consentire o meno la progettazione della classe. È possibile creare una categoria per qualsiasi nome.
Quando si contrassegna una classe con questo attributo, viene impostata su un membro costante. Quando si desidera controllare il valore di questo attributo nel codice, è necessario specificare il membro costante. La colonna Description nella tabella seguente elenca il membro costante su cui è impostato ogni valore.
La DesignerCategoryAttribute classe definisce le categorie comuni seguenti:
| Categoria | Description |
|---|---|
| Componente | Finestre di progettazione utilizzate con i componenti. L'attributo è impostato sul membro DesignerCategoryAttribute.Componentcostante . |
| Form | Finestre di progettazione utilizzate con i moduli. L'attributo è impostato sul membro DesignerCategoryAttribute.Formcostante . |
| Progettista | Finestre di progettazione utilizzate con le finestre di progettazione. L'attributo è impostato sul membro DesignerCategoryAttribute.Genericcostante . |
| Stringa vuota ("") | Questa è la categoria predefinita. |
Per altre informazioni, vedere Attributi.
Costruttori
| Nome | Descrizione |
|---|---|
| DesignerCategoryAttribute() |
Inizializza una nuova istanza della DesignerCategoryAttribute classe con una stringa vuota (""). |
| DesignerCategoryAttribute(String) |
Inizializza una nuova istanza della DesignerCategoryAttribute classe con il nome della categoria specificato. |
Campi
| Nome | Descrizione |
|---|---|
| Component |
Specifica che un componente contrassegnato con questa categoria utilizza una finestra di progettazione componenti. Questo campo è di sola lettura. |
| Default |
Specifica che un componente contrassegnato con questa categoria non può utilizzare una finestra di progettazione visiva. Questo |
| Form |
Specifica che un componente contrassegnato con questa categoria utilizza una finestra di progettazione moduli. Questo |
| Generic |
Specifica che un componente contrassegnato con questa categoria utilizza una finestra di progettazione generica. Questo |
Proprietà
| Nome | Descrizione |
|---|---|
| Category |
Ottiene il nome della categoria. |
| TypeId |
Ottiene un identificatore univoco per questo attributo. |
Metodi
| Nome | Descrizione |
|---|---|
| Equals(Object) |
Restituisce un valore che indica se il valore dell'oggetto specificato è uguale all'oggetto corrente DesignOnlyAttribute. |
| GetHashCode() |
Restituisce il codice hash per questa istanza. |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| IsDefaultAttribute() |
Determina se questo attributo è l'impostazione predefinita. |
| Match(Object) |
Quando sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza è uguale a un oggetto specificato. (Ereditato da Attribute) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
Implementazioni dell'interfaccia esplicita
| Nome | Descrizione |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Esegue il mapping di un set di nomi a un set corrispondente di identificatori dispatch. (Ereditato da Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera le informazioni sul tipo per un oggetto, che può essere utilizzato per ottenere le informazioni sul tipo per un'interfaccia. (Ereditato da Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Recupera il numero di interfacce di informazioni sul tipo fornite da un oggetto (0 o 1). (Ereditato da Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Fornisce l'accesso alle proprietà e ai metodi esposti da un oggetto . (Ereditato da Attribute) |