다음을 통해 공유


ComponentEventHandler 대리자

정의

구성 요소 수준의 이벤트에서 발생한 ComponentAdding , ComponentAdded , ComponentRemovingComponentRemoved 이벤트를 처리하는 메서드를 나타냅니다.

public delegate void ComponentEventHandler(System::Object ^ sender, ComponentEventArgs ^ e);
public delegate void ComponentEventHandler(object sender, ComponentEventArgs e);
public delegate void ComponentEventHandler(object? sender, ComponentEventArgs e);
[System.Runtime.InteropServices.ComVisible(true)]
public delegate void ComponentEventHandler(object sender, ComponentEventArgs e);
type ComponentEventHandler = delegate of obj * ComponentEventArgs -> unit
[<System.Runtime.InteropServices.ComVisible(true)>]
type ComponentEventHandler = delegate of obj * ComponentEventArgs -> unit
Public Delegate Sub ComponentEventHandler(sender As Object, e As ComponentEventArgs)

매개 변수

sender
Object

이벤트 소스입니다.

e
ComponentEventArgs

이벤트 데이터를 포함하는 ComponentEventArgs입니다.

특성

예제

다음 예제에서는 등록 하 고 ComponentEventHandler 처리 하는 ComponentAdded, , ComponentAddingComponentRemovedComponentRemoving 이벤트입니다.

public:
   void LinkComponentEvent( IComponentChangeService^ changeService )
   {
      // Registers an event handler for the ComponentAdded,
      // ComponentAdding, ComponentRemoved, and ComponentRemoving events.
      changeService->ComponentAdded += gcnew ComponentEventHandler(
         this, &ComponentEventHandlerExample::OnComponentEvent );
      changeService->ComponentAdding += gcnew ComponentEventHandler(
         this, &ComponentEventHandlerExample::OnComponentEvent );
      changeService->ComponentRemoved += gcnew ComponentEventHandler(
         this, &ComponentEventHandlerExample::OnComponentEvent );
      changeService->ComponentRemoving += gcnew ComponentEventHandler(
         this, &ComponentEventHandlerExample::OnComponentEvent );
   }

private:
   void OnComponentEvent( Object^ sender, ComponentEventArgs^ e )
   {
      // Displays changed component information on the console.
      if ( e->Component->Site != nullptr )
      {
         Console::WriteLine( "Name of the component related to the event: " +
            e->Component->Site->Name );
      }
      Console::WriteLine( "Type of the component related to the event: " +
         e->Component->GetType()->FullName );
   }
public void LinkComponentEvent(IComponentChangeService changeService)
{
    // Registers an event handler for the ComponentAdded,
    // ComponentAdding, ComponentRemoved, and ComponentRemoving events.
    changeService.ComponentAdded += new ComponentEventHandler(this.OnComponentEvent);            
    changeService.ComponentAdding += new ComponentEventHandler(this.OnComponentEvent);            
    changeService.ComponentRemoved += new ComponentEventHandler(this.OnComponentEvent);            
    changeService.ComponentRemoving += new ComponentEventHandler(this.OnComponentEvent);                        
}

private void OnComponentEvent(object sender, ComponentEventArgs e)
{
    // Displays changed component information on the console.            
    if( e.Component.Site != null )
        Console.WriteLine("Name of the component related to the event: "+e.Component.Site.Name);      
    Console.WriteLine("Type of the component related to the event: "+e.Component.GetType().FullName);
}
Public Sub LinkComponentEvent(ByVal changeService As IComponentChangeService)
    ' Registers an event handler for the ComponentAdded,
    ' ComponentAdding, ComponentRemoved, and ComponentRemoving events.
    AddHandler changeService.ComponentAdded, AddressOf Me.OnComponentEvent
    AddHandler changeService.ComponentAdding, AddressOf Me.OnComponentEvent
    AddHandler changeService.ComponentRemoved, AddressOf Me.OnComponentEvent
    AddHandler changeService.ComponentRemoving, AddressOf Me.OnComponentEvent
End Sub

Private Sub OnComponentEvent(ByVal sender As Object, ByVal e As ComponentEventArgs)
    ' Displays changed component information on the console.            
    If (e.Component.Site IsNot Nothing) Then
        Console.WriteLine(("Name of the component related to the event: " + e.Component.Site.Name))
    End If
End Sub

설명

ComponentEventHandler 대리자를 만들 때, 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보