ComponentChangedEventHandler 委托
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示用来处理 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
事件源。
- 属性
示例
此示例演示如何注册 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 委托时,需要标识将处理该事件的方法。 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。 有关事件处理程序委托的详细信息,请参阅 处理和引发事件。
ComponentChanged加载或卸载窗体期间不会发生事件,因为这些操作期间需要更改。
扩展方法
GetMethodInfo(Delegate) |
获取指示指定委托表示的方法的对象。 |