PropertyDescriptorCollection.Item[] Proprietà

Definizione

Ottiene o imposta l'oggetto specificato PropertyDescriptor.

Overload

Nome Descrizione
Item[Int32]

Ottiene o imposta l'oggetto PropertyDescriptor in corrispondenza del numero di indice specificato.

Item[String]

Ottiene o imposta l'oggetto PropertyDescriptor con il nome specificato.

Item[Int32]

Origine:
PropertyDescriptorCollection.cs
Origine:
PropertyDescriptorCollection.cs
Origine:
PropertyDescriptorCollection.cs
Origine:
PropertyDescriptorCollection.cs
Origine:
PropertyDescriptorCollection.cs

Ottiene o imposta l'oggetto PropertyDescriptor in corrispondenza del numero di indice specificato.

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

Parametri

index
Int32

Indice in base zero dell'oggetto PropertyDescriptor da ottenere o impostare.

Valore della proprietà

Oggetto PropertyDescriptor con il numero di indice specificato.

Eccezioni

Il index parametro non è un indice valido per Item[Int32].

Esempio

Nell'esempio di codice seguente viene utilizzata la Item[] proprietà per stampare il nome dell'oggetto PropertyDescriptor specificato dal numero di indice in una casella di testo. Poiché il numero di indice è in base zero, in questo esempio viene stampato il nome del secondo PropertyDescriptoroggetto . Richiede che button1 sia stata creata un'istanza in un modulo.

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

Commenti

Il numero di indice è in base zero. Pertanto, è necessario sottrarre 1 dalla posizione numerica di un particolare PropertyDescriptor per accedere a tale PropertyDescriptoroggetto . Ad esempio, per ottenere il terzo PropertyDescriptor, è necessario specificare myColl[2].

Vedi anche

Si applica a

Item[String]

Origine:
PropertyDescriptorCollection.cs
Origine:
PropertyDescriptorCollection.cs
Origine:
PropertyDescriptorCollection.cs
Origine:
PropertyDescriptorCollection.cs
Origine:
PropertyDescriptorCollection.cs

Ottiene o imposta l'oggetto PropertyDescriptor con il nome specificato.

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

Parametri

name
String

Nome dell'oggetto PropertyDescriptor da ottenere dalla raccolta.

Valore della proprietà

Oggetto PropertyDescriptor con il nome specificato o null se la proprietà non esiste.

Esempio

Nell'esempio di codice seguente viene utilizzata la Item[] proprietà per stampare il tipo di componente per l'oggetto PropertyDescriptor specificato dall'indice. Richiede che button1 e textBox1 sia stata creata un'istanza in un modulo.

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

Commenti

La Item[] proprietà fa distinzione tra maiuscole e minuscole durante la ricerca di nomi. Ovvero, i nomi "Pname" e "pname" sono considerati due proprietà diverse.

Vedi anche

Si applica a