PropertyDescriptorCollection.Item[] 屬性

定義

取得或設定指定的 PropertyDescriptor

多載

Item[Int32]

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

Item[String]

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

Item[Int32]

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

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

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

參數

index
Int32

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

屬性值

具有指定索引編號的 PropertyDescriptor

例外狀況

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

範例

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

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

備註

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

另請參閱

適用於

Item[String]

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

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

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

參數

name
String

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

屬性值

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

範例

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

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

備註

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

另請參閱

適用於