PropertyDescriptorCollection.Find 方法

返回具有指定名称的 PropertyDescriptor,使用布尔值指示是否忽略大小写。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
Public Overridable Function Find ( _
    name As String, _
    ignoreCase As Boolean _
) As PropertyDescriptor
用法
Dim instance As PropertyDescriptorCollection
Dim name As String
Dim ignoreCase As Boolean
Dim returnValue As PropertyDescriptor

returnValue = instance.Find(name, ignoreCase)
public virtual PropertyDescriptor Find (
    string name,
    bool ignoreCase
)
public:
virtual PropertyDescriptor^ Find (
    String^ name, 
    bool ignoreCase
)
public PropertyDescriptor Find (
    String name, 
    boolean ignoreCase
)
public function Find (
    name : String, 
    ignoreCase : boolean
) : PropertyDescriptor

参数

  • ignoreCase
    如果要忽略属性名称的大小写,则为 true;否则为 false

返回值

具有指定名称的 PropertyDescriptor,或者如果该属性不存在,则为 空引用(在 Visual Basic 中为 Nothing)。

示例

下面的代码示例查找特定的 PropertyDescriptor。它在文本框中输出此 PropertyDescriptor 的组件类型。它要求已在窗体上实例化 button1textBox1

Private Sub FindProperty()
    ' Creates a new collection and assign it the properties for button1.
    Dim properties As PropertyDescriptorCollection = _
       TypeDescriptor.GetProperties(button1)
       
    ' Sets a PropertyDescriptor to the specific property.
    Dim myProperty As PropertyDescriptor = properties.Find("Opacity", False)
       
    ' Prints the property and the property description.
    textBox1.Text = myProperty.DisplayName & _
       Microsoft.VisualBasic.ControlChars.Cr & myProperty.Description
End Sub
private void FindProperty() {
   // Creates a new collection and assign it the properties for button1.
   PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);

   // Sets a PropertyDescriptor to the specific property.
   PropertyDescriptor myProperty = properties.Find("Opacity", false);

   // Prints the property and the property description.
   textBox1.Text = myProperty.DisplayName + '\n' + myProperty.Description;
}
private:
   void FindProperty()
   {
      // Creates a new collection and assign it the properties for button1.
      PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
      
      // Sets a PropertyDescriptor to the specific property.
      PropertyDescriptor^ myProperty = properties->Find( "Opacity", false );
      
      // Prints the property and the property description.
      textBox1->Text = myProperty->DisplayName + "\n" + myProperty->Description;
   }
private void FindProperty()
{
    // Creates a new collection and assign it the properties for button1.
    PropertyDescriptorCollection properties = 
        TypeDescriptor.GetProperties(button1);

    // Sets a PropertyDescriptor to the specific property.
    PropertyDescriptor myProperty = properties.Find("Opacity", false);

    // Prints the property and the property description.
    textBox1.set_Text(myProperty.get_DisplayName() + '\n' 
        + myProperty.get_Description());
} //FindProperty

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

PropertyDescriptorCollection 类
PropertyDescriptorCollection 成员
System.ComponentModel 命名空间
PropertyDescriptor 类
TypeDescriptor