PropertyDescriptorCollection.Item[] 屬性

定義

取得或設定指定的 PropertyDescriptor

多載

Item[Int32]

取得或設定在指定索引編號的 PropertyDescriptor

Item[String]

取得或設定具有指定之名稱的 PropertyDescriptor

Item[Int32]

來源:
PropertyDescriptorCollection.cs
來源:
PropertyDescriptorCollection.cs
來源:
PropertyDescriptorCollection.cs

取得或設定在指定索引編號的 PropertyDescriptor

C#
public virtual System.ComponentModel.PropertyDescriptor this[int index] { get; }

參數

index
Int32

要取得或設定的 PropertyDescriptor 的以零起始的索引。

屬性值

具有指定索引編號的 PropertyDescriptor

例外狀況

index 參數不是 Item[Int32] 的有效索引。

範例

下列程式代碼範例會 Item[] 使用 屬性,在文字框中列印索引編號所指定的 名稱 PropertyDescriptor 。 因為索引編號是以零起始,所以本範例會列印第二個 PropertyDescriptor的名稱。 它需要 button1 已在表單上具現化。

C#
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();
 }

備註

索引編號是以零起始。 因此,您必須從特定 PropertyDescriptor 的數值位置減去 1,才能存取該 PropertyDescriptor。 例如,若要取得第三 PropertyDescriptor個 ,您需要指定 myColl[2]

另請參閱

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Item[String]

來源:
PropertyDescriptorCollection.cs
來源:
PropertyDescriptorCollection.cs
來源:
PropertyDescriptorCollection.cs

取得或設定具有指定之名稱的 PropertyDescriptor

C#
public virtual System.ComponentModel.PropertyDescriptor this[string name] { get; }
C#
public virtual System.ComponentModel.PropertyDescriptor? this[string name] { get; }

參數

name
String

要從集合中取得的 PropertyDescriptor 名稱。

屬性值

具有指定名稱的 PropertyDescriptornull (如果屬性不存在)。

範例

下列程式代碼範例會 Item[] 使用 屬性來列印索引所指定 之的元件 PropertyDescriptor 類型。 它要求 button1 已在表單上具現化 和 textBox1

C#
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;
}

備註

搜尋名稱時, Item[] 屬性會區分大小寫。 也就是說,名稱 「Pname」 和 「pname」 會被視為兩個不同的屬性。

另請參閱

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1