PropertyDescriptorCollection.Item[] Propriété

Définition

Obtient ou définit le PropertyDescriptor spécifié.

Surcharges

Item[Int32]

Obtient ou définit le PropertyDescriptor situé au numéro d'index spécifié.

Item[String]

Obtient ou définit PropertyDescriptor portant le nom spécifié.

Item[Int32]

Obtient ou définit le PropertyDescriptor situé au numéro d'index spécifié.

public:
 virtual property System::ComponentModel::PropertyDescriptor ^ default[int] { System::ComponentModel::PropertyDescriptor ^ get(int index); };
public virtual System.ComponentModel.PropertyDescriptor this[int index] { get; }
member this.Item(int) : System.ComponentModel.PropertyDescriptor
Default Public Overridable ReadOnly Property Item(index As Integer) As PropertyDescriptor

Paramètres

index
Int32

Index de base zéro du PropertyDescriptor à obtenir ou définir.

Valeur de propriété

PropertyDescriptor

PropertyDescriptor avec le numéro d'index spécifié.

Exceptions

Le paramètre index n'est pas un index valide pour Item[Int32].

Exemples

L’exemple de code suivant utilise la Item[] propriété pour imprimer le nom du PropertyDescriptor numéro d’index spécifié dans une zone de texte. Étant donné que le numéro d’index est basé sur zéro, cet exemple imprime le nom du second PropertyDescriptor. Elle exige qu’elle button1 ait été instanciée sur un formulaire.

void PrintIndexItem()
{
   
   // Creates a new collection and assigns it the properties for button1.
   PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
   
   // Prints the second property's name.
   textBox1->Text = properties[ 1 ]->ToString();
}
private void PrintIndexItem() {
    // Creates a new collection and assigns it the properties for button1.
    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);
 
    // Prints the second property's name.
    textBox1.Text = properties[1].ToString();
 }
Private Sub PrintIndexItem()
    ' Creates a new collection and assigns it the properties for button1.
    Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(button1)
       
    ' Prints the second property's name.
    textBox1.Text = properties(1).ToString()
End Sub

Remarques

Le numéro d’index est basé sur zéro. Par conséquent, vous devez soustraire 1 de la position numérique d’un particulier PropertyDescriptor pour y accéder PropertyDescriptor. Par exemple, pour obtenir le troisième PropertyDescriptor, vous devez spécifier myColl[2].

Voir aussi

S’applique à

Item[String]

Obtient ou définit PropertyDescriptor portant le nom spécifié.

public:
 virtual property System::ComponentModel::PropertyDescriptor ^ default[System::String ^] { System::ComponentModel::PropertyDescriptor ^ get(System::String ^ name); };
public virtual System.ComponentModel.PropertyDescriptor this[string name] { get; }
public virtual System.ComponentModel.PropertyDescriptor? this[string name] { get; }
member this.Item(string) : System.ComponentModel.PropertyDescriptor
Default Public Overridable ReadOnly Property Item(name As String) As PropertyDescriptor

Paramètres

name
String

Nom du PropertyDescriptor à obtenir à partir de la collection.

Valeur de propriété

PropertyDescriptor

PropertyDescriptor portant le nom spécifié, ou null si aucune propriété n'existe.

Exemples

L’exemple de code suivant utilise la Item[] propriété pour imprimer le type de composant pour l’index PropertyDescriptor spécifié. Elle exige qu’elle button1 ait textBox1 été instanciée sur un formulaire.

void PrintIndexItem2()
{
   
   // Creates a new collection and assigns it the properties for button1.
   PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
   
   // Sets a PropertyDescriptor to the specific property.
   PropertyDescriptor^ myProperty = properties[ "Opacity" ];
   
   // Prints the display name for the property.
   textBox1->Text = myProperty->DisplayName;
}
private void PrintIndexItem2() {
   // Creates a new collection and assigns it the properties for button1.
   PropertyDescriptorCollection properties =
       TypeDescriptor.GetProperties(button1);

   // Sets a PropertyDescriptor to the specific property.
   PropertyDescriptor myProperty = properties["Opacity"];

   // Prints the display name for the property.
   textBox1.Text = myProperty.DisplayName;
}
Private Sub PrintIndexItem2()
    ' Creates a new collection and assigns it the properties for button1.
    Dim properties As PropertyDescriptorCollection = _
       TypeDescriptor.GetProperties(button1)
       
    ' Sets a PropertyDescriptor to the specific property.
    Dim myProperty As PropertyDescriptor = properties("Opacity")
       
    ' Prints the display name for the property.
    textBox1.Text = myProperty.DisplayName
End Sub

Remarques

La propriété respecte la Item[] casse lors de la recherche de noms. Autrement dit, les noms « Pname » et « pname » sont considérés comme deux propriétés différentes.

Voir aussi

S’applique à