PropertyDescriptorCollection.Item[] 属性

定义

获取或设置指定的 PropertyDescriptor

重载

名称 说明
Item[Int32]

获取或设置 PropertyDescriptor 指定索引号处。

Item[String]

获取或设置 PropertyDescriptor 具有指定名称。

Item[Int32]

Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs
Source:
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]

Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs
Source:
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

属性值

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”被视为两个不同的属性。

另请参阅

适用于