Partilhar via


ComponentChangedEventHandler Delegar

Definição

Representa o método que irá manipular um evento de ComponentChanged .

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

Parâmetros

sender
Object

A fonte do evento.

e
ComponentChangedEventArgs

Um ComponentChangedEventArgs que contém os dados do evento.

Atributos

Exemplos

Este exemplo demonstra o registro de um ComponentChangedEventHandler e a manipulação do ComponentChanged evento.

public:
   void LinkComponentChangedEvent( IComponentChangeService^ changeService )
   {
      // Registers an event handler for the ComponentChanged event.
      changeService->ComponentChanged += gcnew ComponentChangedEventHandler(
         this, &ComponentChangedEventHandlerExample::OnComponentChanged );
   }

private:
   void OnComponentChanged( Object^ sender, ComponentChangedEventArgs^ e )
   {
      // Displays changed component information on the console.
      Console::WriteLine( "Type of the component that has changed: " +
         e->Component->GetType()->FullName );
      Console::WriteLine( "Name of the member of the component that has changed: " +
         e->Member->Name );
      Console::WriteLine( "Old value of the member: " + e->OldValue );
      Console::WriteLine( "New value of the member: " + e->NewValue );
   }
public void LinkComponentChangedEvent(IComponentChangeService changeService)
{
    // Registers an event handler for the ComponentChanged event.
    changeService.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);            
}

private void OnComponentChanged(object sender, ComponentChangedEventArgs e)
{
    // Displays changed component information on the console.
    Console.WriteLine("Type of the component that has changed: "+e.Component.GetType().FullName);      
    Console.WriteLine("Name of the member of the component that has changed: "+e.Member.Name);            
    Console.WriteLine("Old value of the member: "+e.OldValue.ToString());
    Console.WriteLine("New value of the member: "+e.NewValue.ToString());
}
Public Sub LinkComponentChangedEvent(ByVal changeService As IComponentChangeService)
    ' Registers an event handler for the ComponentChanged event.
    AddHandler changeService.ComponentChanged, AddressOf Me.OnComponentChanged
End Sub

Private Sub OnComponentChanged(ByVal sender As Object, ByVal e As ComponentChangedEventArgs)
    ' Displays changed component information on the console.            
    Console.WriteLine(("Type of the component that has changed: " + e.Component.GetType().FullName))
    Console.WriteLine(("Name of the member of the component that has changed: " + e.Member.Name))
    Console.WriteLine(("Old value of the member: " + e.OldValue.ToString()))
    Console.WriteLine(("New value of the member: " + e.NewValue.ToString()))
End Sub

Comentários

Ao criar um ComponentChangedEventHandler delegado, você identifica o método que manipulará o evento. Para associar o evento ao manipulador de eventos, adicione uma instância do delegado ao evento. O manipulador de eventos é chamado sempre que o evento ocorre, a menos que você remova o representante. Para obter mais informações sobre delegados do manipulador de eventos, consulte Manipulando e levantando eventos.

Um ComponentChanged evento não ocorrerá durante o carregamento ou descarregamento de um formulário porque são esperadas alterações durante essas operações.

Métodos de Extensão

GetMethodInfo(Delegate)

Obtém um objeto que representa o método representado pelo delegado especificado.

Aplica-se a

Confira também