PropertyDescriptorCollection.Item[] Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar eller anger den angivna PropertyDescriptor.
Överlagringar
| Name | Description |
|---|---|
| Item[Int32] |
Hämtar eller anger PropertyDescriptor det angivna indexnumret. |
| Item[String] |
Hämtar eller anger PropertyDescriptor med det angivna namnet. |
Item[Int32]
Hämtar eller anger PropertyDescriptor det angivna indexnumret.
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
Parametrar
- index
- Int32
Det nollbaserade indexet för att PropertyDescriptor hämta eller ange.
Egenskapsvärde
Med PropertyDescriptor det angivna indexnumret.
Undantag
Parametern index är inte ett giltigt index för Item[Int32].
Exempel
I följande kodexempel används Item[] egenskapen för att skriva ut namnet på det PropertyDescriptor som anges av indexnumret i en textruta. Eftersom indexnumret är nollbaserat skriver det här exemplet ut namnet på den andra PropertyDescriptor. Det kräver att button1 det har instansierats i ett formulär.
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
Kommentarer
Indexnumret är nollbaserat. Därför måste du subtrahera 1 från den numeriska positionen för en viss PropertyDescriptor för att få åtkomst till den PropertyDescriptor. Om du till exempel vill hämta den tredje PropertyDescriptormåste du ange myColl[2].
Se även
Gäller för
Item[String]
Hämtar eller anger PropertyDescriptor med det angivna namnet.
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; }
member this.Item(string) : System.ComponentModel.PropertyDescriptor
Default Public Overridable ReadOnly Property Item(name As String) As PropertyDescriptor
Parametrar
- name
- String
Namnet på den PropertyDescriptor som ska hämtas från samlingen.
Egenskapsvärde
Med PropertyDescriptor det angivna namnet eller null om egenskapen inte finns.
Exempel
I följande kodexempel används Item[] egenskapen för att skriva ut komponenttypen för den PropertyDescriptor som anges av indexet. Det kräver det button1 och textBox1 har instansierats i ett formulär.
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
Kommentarer
Egenskapen Item[] är skiftlägeskänslig när du söker efter namn. Det vill: namnen "Pname" och "pname" anses vara två olika egenskaper.