Bagikan melalui


DesignerEventHandler Delegasikan

Definisi

Mewakili metode yang akan menangani DesignerCreated peristiwa dan DesignerDisposed yang dimunculkan saat dokumen dibuat atau dibuang.

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)

Parameter

sender
Object

Sumber dari peristiwa tersebut.

e
DesignerEventArgs

DesignerEventArgs yang berisi data peristiwa.

Contoh

Contoh berikut menunjukkan mendaftarkan DesignerEventHandler dan menangani DesignerCreated peristiwa dan DesignerDisposed .

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

Keterangan

Saat membuat DesignerEventHandler delegasi, Anda mengidentifikasi metode yang akan menangani peristiwa. Untuk mengaitkan peristiwa dengan penanganan aktivitas Anda, tambahkan instans delegasi ke peristiwa. Penanganan aktivitas dipanggil setiap kali peristiwa terjadi, kecuali Jika Anda menghapus delegasi. Untuk informasi selengkapnya tentang delegasi penanganan aktivitas, lihat Menangani dan Meningkatkan Peristiwa.

Metode Ekstensi

GetMethodInfo(Delegate)

Mendapatkan objek yang mewakili metode yang diwakili oleh delegasi yang ditentukan.

Berlaku untuk

Lihat juga