ComponentRenameEventHandler 代理人

定義

代表將處理事件 ComponentRename 的方法。

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

參數

sender
Object

事件的 來源。

屬性

範例

以下範例示範註冊 a ComponentRenameEventHandler 並處理 ComponentRename 事件。

public:
   void LinkComponentRenameEvent( IComponentChangeService^ changeService )
   {
      // Registers an event handler for the ComponentRename event.
      changeService->ComponentRename += gcnew ComponentRenameEventHandler(
         this, &ComponentRenameEventHandlerExample::OnComponentRename );
   }

private:
   void OnComponentRename( Object^ /*sender*/, ComponentRenameEventArgs^ e )
   {
      // Displayss component renamed information on the console.
      Console::WriteLine( "Type of the component that has been renamed: " +
         e->Component->GetType()->FullName );
      Console::WriteLine( "New name of the component that has been renamed: " +
         e->NewName );
      Console::WriteLine( "Old name of the component that has been renamed: " +
         e->OldName );
   }
public void LinkComponentRenameEvent(IComponentChangeService changeService)
{
    // Registers an event handler for the ComponentRename event.
    changeService.ComponentRename += new ComponentRenameEventHandler(this.OnComponentRename);            
}

private void OnComponentRename(object sender, ComponentRenameEventArgs e)
{
    // Displayss component renamed information on the console.           
    Console.WriteLine("Type of the component that has been renamed: "+e.Component.GetType().FullName);                  
    Console.WriteLine("New name of the component that has been renamed: "+e.NewName);
    Console.WriteLine("Old name of the component that has been renamed: "+e.OldName);
}
Public Sub LinkComponentRenameEvent(ByVal changeService As IComponentChangeService)
    ' Registers an event handler for the ComponentRename event.
    AddHandler changeService.ComponentRename, AddressOf Me.OnComponentRename
End Sub

Private Sub OnComponentRename(ByVal sender As Object, ByVal e As ComponentRenameEventArgs)
    ' Displays component renamed information on the console.           
    Console.WriteLine(("Type of the component that has been renamed: " + e.Component.GetType().FullName))
    Console.WriteLine(("New name of the component that has been renamed: " + e.NewName))
    Console.WriteLine(("Old name of the component that has been renamed: " + e.OldName))
End Sub

備註

當你建立 ComponentRenameEventHandler 代理人時,你就能確定處理事件的方法。 要將事件與你的事件處理器關聯,請將該代理的實例加入事件中。 事件處理程序會在事件發生時被呼叫,除非你移除代理。 欲了解更多關於事件處理代表的資訊,請參閱 「處理與提升事件」。

擴充方法

名稱 Description
GetMethodInfo(Delegate)

取得一個代表指定代理所代表方法的物件。

適用於

另請參閱