DesignerEventHandler 委托

定义

表示要处理 DesignerCreatedDesignerDisposed 事件的方法,这两种事件在创建或释放文档时引发。

public delegate void DesignerEventHandler(System::Object ^ sender, DesignerEventArgs ^ e);
public delegate void DesignerEventHandler(object sender, DesignerEventArgs e);
public delegate void DesignerEventHandler(object? sender, DesignerEventArgs e);
type DesignerEventHandler = delegate of obj * DesignerEventArgs -> unit
Public Delegate Sub DesignerEventHandler(sender As Object, e As DesignerEventArgs)

参数

sender
Object

事件源。

e
DesignerEventArgs

包含事件数据的 DesignerEventArgs

示例

以下示例演示如何注册 DesignerEventHandler 并处理 DesignerCreatedDesignerDisposed 事件。

public:
   void LinkDesignerEvent( IDesignerEventService^ eventService )
   {
      // Registers an event handler for the DesignerCreated and DesignerDisposed events.
      eventService->DesignerCreated += gcnew DesignerEventHandler(
         this, &DesignerEventHandlerExample::OnDesignerEvent );
      eventService->DesignerDisposed += gcnew DesignerEventHandler(
         this, &DesignerEventHandlerExample::OnDesignerEvent );
   }

private:
   void OnDesignerEvent( Object^ sender, DesignerEventArgs^ e )
   {
      // Displays designer event information on the console.
      Console::WriteLine( "Name of the root component of the created or disposed designer: " +
         e->Designer->RootComponentClassName );
   }
public void LinkDesignerEvent(IDesignerEventService eventService)
{                                   
    // Registers an event handler for the DesignerCreated and DesignerDisposed events.
    eventService.DesignerCreated += new DesignerEventHandler(this.OnDesignerEvent);
    eventService.DesignerDisposed += new DesignerEventHandler(this.OnDesignerEvent);            
}

private void OnDesignerEvent(object sender, DesignerEventArgs e)
{
    // Displays designer event information on the console.
    Console.WriteLine("Name of the root component of the created or disposed designer: "+e.Designer.RootComponentClassName);
}
Public Sub LinkDesignerEvent(ByVal eventService As IDesignerEventService)
    ' Registers an event handler for the DesignerCreated and DesignerDisposed events.
    AddHandler eventService.DesignerCreated, AddressOf Me.OnDesignerEvent
    AddHandler eventService.DesignerDisposed, AddressOf Me.OnDesignerEvent
End Sub

Private Sub OnDesignerEvent(ByVal sender As Object, ByVal e As DesignerEventArgs)
    ' Displays designer event information on the console.
    Console.WriteLine(("Name of the root component of the created or disposed designer: " + e.Designer.RootComponentClassName))
End Sub

注解

创建 DesignerEventHandler 委托时,需要标识将处理该事件的方法。 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。 有关事件处理程序委托的详细信息,请参阅 处理和引发事件

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。

适用于

另请参阅