PropertyDescriptorCollection.Item[] Właściwość

Definicja

Pobiera lub ustawia określony PropertyDescriptorelement .

Przeciążenia

Item[Int32]

Pobiera lub ustawia wartość PropertyDescriptor w określonym numerze indeksu.

Item[String]

Pobiera lub ustawia element PropertyDescriptor o określonej nazwie.

Item[Int32]

Źródło:
PropertyDescriptorCollection.cs
Źródło:
PropertyDescriptorCollection.cs
Źródło:
PropertyDescriptorCollection.cs

Pobiera lub ustawia wartość PropertyDescriptor w określonym numerze indeksu.

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

Parametry

index
Int32

Indeks zerowy PropertyDescriptor klasy , który ma być pobierany lub ustawiany.

Wartość właściwości

Element PropertyDescriptor z określonym numerem indeksu.

Wyjątki

Parametr index nie jest prawidłowym indeksem dla .Item[Int32]

Przykłady

Poniższy przykład kodu używa Item[] właściwości do drukowania nazwy PropertyDescriptor określonej przez numer indeksu w polu tekstowym. Ponieważ numer indeksu jest oparty na zerze, w tym przykładzie jest wyświetlana nazwa drugiego PropertyDescriptorelementu . Wymaga button1 utworzenia wystąpienia formularza.

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

Uwagi

Liczba indeksu jest oparta na zera. W związku z tym należy odjąć 1 od pozycji liczbowej określonej PropertyDescriptor , aby uzyskać dostęp do tej wartości PropertyDescriptor. Aby na przykład uzyskać trzeci PropertyDescriptorelement , należy określić wartość myColl[2].

Zobacz też

Dotyczy

Item[String]

Źródło:
PropertyDescriptorCollection.cs
Źródło:
PropertyDescriptorCollection.cs
Źródło:
PropertyDescriptorCollection.cs

Pobiera lub ustawia element PropertyDescriptor o określonej nazwie.

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

Parametry

name
String

Nazwa elementu PropertyDescriptor do pobrania z kolekcji.

Wartość właściwości

Właściwość PropertyDescriptor o określonej nazwie lub null jeśli właściwość nie istnieje.

Przykłady

Poniższy przykład kodu używa Item[] właściwości do drukowania typu składnika określonego PropertyDescriptor przez indeks. Wymaga to utworzenia button1textBox1 wystąpienia i utworzenia wystąpienia w formularzu.

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

Uwagi

Właściwość Item[] uwzględnia wielkość liter podczas wyszukiwania nazw. Oznacza to, że nazwy "Pname" i "pname" są uważane za dwie różne właściwości.

Zobacz też

Dotyczy