共用方式為


ComponentChangedEventHandler 代理人

定義

代表將處理 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)

參數

sender
Object

事件的來源。

e
ComponentChangedEventArgs

ComponentChangedEventArgs,其中包含事件資料。

屬性

範例

此範例示範註冊 ComponentChangedEventHandler 和處理 ComponentChanged 事件。

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

備註

建立 ComponentChangedEventHandler 委派時,必須識別處理事件的方法。 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。 除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。 如需事件處理程式委派的詳細資訊,請參閱 處理和引發事件

ComponentChanged載入或卸除表單期間不會發生事件,因為這些作業期間預期會有變更。

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。

適用於

另請參閱