EventDescriptorCollection.Find(String, Boolean) 方法

定义

获取集合中具有指定名称的事件的说明。

public:
 virtual System::ComponentModel::EventDescriptor ^ Find(System::String ^ name, bool ignoreCase);
public virtual System.ComponentModel.EventDescriptor Find (string name, bool ignoreCase);
public virtual System.ComponentModel.EventDescriptor? Find (string name, bool ignoreCase);
abstract member Find : string * bool -> System.ComponentModel.EventDescriptor
override this.Find : string * bool -> System.ComponentModel.EventDescriptor
Public Overridable Function Find (name As String, ignoreCase As Boolean) As EventDescriptor

参数

name
String

要从集合中获取的事件的名称。

ignoreCase
Boolean

如果要忽略事件的大小写,则为 true;否则为 false

返回

具有指定名称的 EventDescriptor,或者如果该事件不存在,则为 null

示例

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

private:
   void FindEvent()
   {
      // Creates a new collection and assigns it the events for button1.
      EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );
      
      // Sets an EventDescriptor to the specific event.
      EventDescriptor^ myEvent = events->Find( "Resize", false );
      
      // Prints the event name and event description.
      textBox1->Text = String::Concat( myEvent->Name, ": ", myEvent->Description );
   }
private void FindEvent() {
    // Creates a new collection and assigns it the events for button1.
    EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);
 
    // Sets an EventDescriptor to the specific event.
    EventDescriptor myEvent = events.Find("Resize", false);
 
    // Prints the event name and event description.
    textBox1.Text = myEvent.Name + ": " + myEvent.Description;
 }
Private Sub FindEvent()
    ' Creates a new collection and assigns it the events for button1.
    Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(button1)
    
    ' Sets an EventDescriptor to the specific event.
    Dim myEvent As EventDescriptor = events.Find("Resize", False)
    
    ' Prints the event name and event description.
    textBox1.Text = myEvent.Name & ": " & myEvent.Description
End Sub

注解

注意

HostProtectionAttribute应用于此类的属性具有以下Resources属性值:SynchronizationHostProtectionAttribute 不影响桌面应用程序(通常通过双击图标、键入命令或在浏览器中输入 URL 来启动这些应用程序)。 有关详细信息,请参阅 HostProtectionAttribute 类或SQL Server编程和主机保护属性

适用于

另请参阅