PropertyDescriptorCollection.Item[] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定指定的 PropertyDescriptor。
多載
| 名稱 | Description |
|---|---|
| Item[Int32] |
取得或設定 PropertyDescriptor 為指定的索引號。 |
| Item[String] |
取得或設定指定名稱的 。PropertyDescriptor |
Item[Int32]
取得或設定 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
就是 to get 或 set 的 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]
取得或設定指定名稱的 。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 。
屬性值
該 PropertyDescriptor 名稱為該性質,或 null 是該性質不存在。
範例
以下程式碼範例使用該 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」這兩個名稱被視為兩個不同的性質。