CategoryAttribute Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Spécifie le nom de la catégorie dans laquelle regrouper la propriété ou l’événement lorsqu’il est affiché dans un contrôle PropertyGrid défini sur Le mode Catégorisé.
public ref class CategoryAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public class CategoryAttribute : Attribute
public class CategoryAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type CategoryAttribute = class
inherit Attribute
type CategoryAttribute = class
inherit Attribute
Public Class CategoryAttribute
Inherits Attribute
- Héritage
- Attributs
Exemples
L’exemple suivant crée la MyImage propriété. La propriété a deux attributs : a DescriptionAttribute et a CategoryAttribute.
[Description("The image associated with the control"),Category("Appearance")]
System::Drawing::Image^ get()
{
// Insert code here.
return m_Image1;
}
void set( System::Drawing::Image^ )
{
// Insert code here.
}
}
[Description("The image associated with the control"), Category("Appearance")]
public Image MyImage
{
get =>
// Insert code here.
image1;
set
{
// Insert code here.
}
}
<Description("The image associated with the control"), _
Category("Appearance")> _
Public Property MyImage() As Image
Get
' Insert code here.
Return image1
End Get
Set
' Insert code here.
End Set
End Property
L’exemple suivant obtient la catégorie pour MyImage. Tout d’abord, le code obtient une PropertyDescriptorCollection valeur avec toutes les propriétés de l’objet. Ensuite, le code indexe dans l’obtention PropertyDescriptorCollectionMyImage. Ensuite, elle retourne les attributs de cette propriété et les enregistre dans la variable attributes.
L’exemple imprime ensuite la catégorie en récupérant à partir de l’écran AttributeCollectionde console et en l’écrivant CategoryAttribute dans l’écran de console.
// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyImage" ]->Attributes;
// Prints the description by retrieving the CategoryAttribute.
// from the AttributeCollection.
CategoryAttribute^ myAttribute = static_cast<CategoryAttribute^>(attributes[ CategoryAttribute::typeid ]);
Console::WriteLine( myAttribute->Category );
// Gets the attributes for the property.
AttributeCollection attributes =
TypeDescriptor.GetProperties(this)["MyImage"].Attributes;
// Prints the description by retrieving the CategoryAttribute.
// from the AttributeCollection.
CategoryAttribute myAttribute =
(CategoryAttribute)attributes[typeof(CategoryAttribute)];
Console.WriteLine(myAttribute.Category);
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
TypeDescriptor.GetProperties(Me)("MyImage").Attributes
' Prints the description by retrieving the CategoryAttribute.
' from the AttributeCollection.
Dim myAttribute As CategoryAttribute = _
CType(attributes(GetType(CategoryAttribute)), CategoryAttribute)
Console.WriteLine(myAttribute.Category)
Remarques
A CategoryAttribute indique la catégorie à laquelle associer la propriété ou l’événement associé, lors de la liste des propriétés ou des événements dans un PropertyGrid contrôle défini sur Categorized mode. S’il CategoryAttribute n’a pas été appliqué à une propriété ou à un événement, il l’associe PropertyGrid à la catégorie Misc . Une nouvelle catégorie peut être créée pour n’importe quel nom en spécifiant le nom de la catégorie dans le constructeur pour le CategoryAttribute.
La Category propriété indique le nom de la catégorie que l’attribut représente. La Category propriété fournit également une localisation transparente des noms de catégorie.
Notes pour les héritiers
Si vous utilisez des noms de catégorie autres que les noms prédéfinis et que vous souhaitez localiser vos noms de catégorie, vous devez remplacer la GetLocalizedString(String) méthode.
La CategoryAttribute classe définit les catégories courantes suivantes :
| Category | Description |
|---|---|
| Action | Propriétés liées aux actions disponibles. |
| Appearance | Propriétés liées à l’affichage d’une entité. |
| Behavior | Propriétés liées à la façon dont une entité agit. |
| Data | Propriétés liées à la gestion des données et des sources de données. |
| Default | Propriétés regroupées dans une catégorie par défaut. |
| Design | Propriétés disponibles uniquement au moment du design. |
| DragDrop | Propriétés liées aux opérations de glisser-déplacer. |
| Focus | Propriétés liées au focus. |
| Format | Propriétés liées à la mise en forme. |
| Key | Propriétés associées au clavier. |
| Layout | Propriétés liées à la disposition. |
| Mouse | Propriétés associées à la souris. |
| WindowStyle | Propriétés liées au style de fenêtre des formulaires de niveau supérieur. |
Pour plus d’informations, consultez Attributs.
Constructeurs
| Nom | Description |
|---|---|
| CategoryAttribute() |
Initialise une nouvelle instance de la CategoryAttribute classe à l’aide du nom de catégorie Par défaut. |
| CategoryAttribute(String) |
Initialise une nouvelle instance de la CategoryAttribute classe à l’aide du nom de catégorie spécifié. |
Propriétés
| Nom | Description |
|---|---|
| Action |
Obtient un CategoryAttribute représentant la catégorie Action. |
| Appearance |
Obtient un CategoryAttribute représentant la catégorie Apparence. |
| Asynchronous |
Obtient un CategoryAttribute représentant la catégorie asynchrone. |
| Behavior |
Obtient un CategoryAttribute représentant la catégorie Comportement. |
| Category |
Obtient le nom de la catégorie pour la propriété ou l’événement auquel cet attribut est appliqué. |
| Data |
Obtient un CategoryAttribute représentant la catégorie Données. |
| Default |
Obtient un CategoryAttribute représentant la catégorie par défaut. |
| Design |
Obtient un CategoryAttribute représentant la catégorie Création. |
| DragDrop |
Obtient un CategoryAttribute représentant la catégorie DragDrop. |
| Focus |
Obtient un CategoryAttribute représentant la catégorie Focus. |
| Format |
Obtient un CategoryAttribute représentant la catégorie Format. |
| Key |
Obtient une CategoryAttribute valeur représentant la catégorie Clé. |
| Layout |
Obtient un CategoryAttribute représentant la catégorie Disposition. |
| Mouse |
Obtient un CategoryAttribute représentant la catégorie souris. |
| TypeId |
En cas d’implémentation dans une classe dérivée, obtient un identificateur unique pour cette Attribute. (Hérité de Attribute) |
| WindowStyle |
Obtient un CategoryAttribute représentant la catégorie WindowStyle. |
Méthodes
| Nom | Description |
|---|---|
| Equals(Object) |
Retourne si la valeur de l’objet donné est égale à la valeur actuelle CategoryAttribute. |
| GetHashCode() |
Retourne le code de hachage de cet attribut. |
| GetLocalizedString(String) |
Recherche le nom localisé de la catégorie spécifiée. |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| IsDefaultAttribute() |
Détermine si cet attribut est la valeur par défaut. |
| Match(Object) |
En cas de substitution dans une classe dérivée, retourne une valeur qui indique si cette instance est égale à un objet spécifié. (Hérité de Attribute) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |
Implémentations d’interfaces explicites
| Nom | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Mappe un jeu de noms avec un jeu correspondant d'identificateurs de dispatch. (Hérité de Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Récupère les informations de type d’un objet, qui peuvent être utilisées pour obtenir les informations de type d’une interface. (Hérité de Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Récupère le nombre d'interfaces d'informations de type fourni par un objet (0 ou 1). (Hérité de Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Fournit l’accès aux propriétés et méthodes exposées par un objet. (Hérité de Attribute) |