PropertyDescriptorCollection.Item[String] 属性

定义

获取或设置指定的 PropertyDescriptorGets or sets the specified PropertyDescriptor.

重载

Item[Int32]

获取或设置指定索引处的 PropertyDescriptorGets or sets the PropertyDescriptor at the specified index number.

Item[String]

获取或设置具有指定名称的 PropertyDescriptorGets or sets the PropertyDescriptor with the specified name.

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

要获取或设置的 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才能访问该PropertyDescriptor数字。Therefore, 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]

获取或设置具有指定名称的 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

要从集合中获取的 PropertyDescriptor 的名称。The name of the PropertyDescriptor to get from the collection.

属性值

具有指定名称的 PropertyDescriptor,或者如果该属性不存在,则为 nullThe 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. 它要求button1在窗textBox1体中实例化和。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.

另请参阅

适用于