PropertyDescriptorCollection.Item[String] PropertyDescriptorCollection.Item[String] PropertyDescriptorCollection.Item[String] PropertyDescriptorCollection.Item[String] Property

定義

多載

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

取得或設定在指定索引編號的 PropertyDescriptorGets or sets the PropertyDescriptor at the specified index number.

Item[String] Item[String] Item[String] Item[String]

取得或設定具有指定之名稱的 PropertyDescriptorGets or sets the PropertyDescriptor with the specified name.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

取得或設定在指定索引編號的 PropertyDescriptorGets or sets the PropertyDescriptor at the specified index number.

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 Int32 Int32 Int32

要取得或設定的 PropertyDescriptor 的以零起始的索引。The zero-based index of the PropertyDescriptor to get or set.

屬性值

具有指定索引編號的 PropertyDescriptorThe PropertyDescriptor with the specified index number.

例外狀況

index 參數不是 Item[Int32] 的有效索引。The index parameter is not a valid index for Item[Int32].

範例

下列程式碼範例會使用Item[String]屬性,在文字方塊中列印索引PropertyDescriptor編號所指定的名稱。The following code example uses the Item[String] property to print the name of the PropertyDescriptor specified by the index number in a text box. 因為索引編號是以零為起始,所以這個範例會列印第二個PropertyDescriptor的名稱。Because the index number is zero-based, this example prints the name of the second PropertyDescriptor. 它需要button1已經在表單上具現化。It requires that button1 has been instantiated on a form.

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

備註

索引編號是以零為基底。The index number is zero-based. 因此,您必須從特定PropertyDescriptor的數位位置減去1,才能存取該。 PropertyDescriptorTherefore, you must subtract 1 from the numerical position of a particular PropertyDescriptor to access that PropertyDescriptor. 例如,若要取得第三PropertyDescriptor個,您必須指定myColl[2]For example, to get the third PropertyDescriptor, you need to specify myColl[2].

另請參閱

Item[String] Item[String] Item[String] Item[String]

取得或設定具有指定之名稱的 PropertyDescriptorGets or sets the PropertyDescriptor with the specified name.

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

參數

name
String String String String

要從集合中取得的 PropertyDescriptor 名稱。The name of the PropertyDescriptor to get from the collection.

屬性值

具有指定名稱的 PropertyDescriptornull (如果屬性不存在)。The PropertyDescriptor with the specified name, or null if the property does not exist.

範例

下列程式碼範例會使用Item[String]屬性,來列印索引所指定之的PropertyDescriptor元件類型。The following code example uses the Item[String] property to print the type of component for the PropertyDescriptor specified by the index. 它需要button1textBox1已經在表單上具現化。It requires that button1 and textBox1 have been instantiated on a form.

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[String]名稱時,屬性會區分大小寫。The Item[String] property is case-sensitive when searching for names. 也就是說,名稱 "Pname" 和 "Pname" 會視為兩個不同的屬性。That is, the names "Pname" and "pname" are considered to be two different properties.

另請參閱

適用於