ActiveDesignerEventHandler 委托
表示将处理 ActiveDesignerChanged 事件的方法。
**命名空间:**System.ComponentModel.Design
**程序集:**System(在 system.dll 中)
语法
声明
Public Delegate Sub ActiveDesignerEventHandler ( _
sender As Object, _
e As ActiveDesignerEventArgs _
)
用法
Dim instance As New ActiveDesignerEventHandler(AddressOf HandlerMethod)
public delegate void ActiveDesignerEventHandler (
Object sender,
ActiveDesignerEventArgs e
)
public delegate void ActiveDesignerEventHandler (
Object^ sender,
ActiveDesignerEventArgs^ e
)
/** @delegate */
public delegate void ActiveDesignerEventHandler (
Object sender,
ActiveDesignerEventArgs e
)
JScript 支持使用委托,但不支持进行新的声明。
参数
- sender
事件源。
- e
包含事件数据的 ActiveDesignerEventArgs。
备注
ActiveDesignerChanged 事件在当前处于活动状态的文档经过修改时引发。
创建 ActiveDesignerEventHandler 委托时,标识将处理事件的方法。若要使该事件与事件处理程序相关联,请将该委托的一个实例添加到事件中。除非移除了该委托,否则每当发生该事件时就调用事件处理程序。有关事件处理程序委托的更多信息,请参见 事件和委托。
提示
应用于此类的 HostProtectionAttribute 属性 (Attribute) 具有以下 Resources 属性 (Property) 值:SharedState。HostProtectionAttribute 不影响桌面应用程序(桌面应用程序一般通过双击图标,键入命令或在浏览器中输入 URL 启动)。有关更多信息,请参见 HostProtectionAttribute 类或 SQL Server 编程和宿主保护属性。
示例
下面的示例演示如何注册 ActiveDesignerEventHandler 和处理 ActiveDesignerChanged 事件。
Public Sub LinkActiveDesignerEvent(ByVal eventService As IDesignerEventService)
' Registers an event handler for the ActiveDesignerChanged event.
AddHandler eventService.ActiveDesignerChanged, AddressOf Me.OnActiveDesignerEvent
End Sub
Private Sub OnActiveDesignerEvent(ByVal sender As Object, ByVal e As ActiveDesignerEventArgs)
' Displays changed designer information on the console.
If Not (e.NewDesigner.RootComponent.Site Is Nothing) Then
Console.WriteLine(("Name of the component of the new active designer: " + e.NewDesigner.RootComponent.Site.Name))
End If
Console.WriteLine(("Type of the component of the new active designer: " + e.NewDesigner.RootComponentClassName))
If Not (e.OldDesigner.RootComponent.Site Is Nothing) Then
Console.WriteLine(("Name of the component of the previously active designer: " + e.OldDesigner.RootComponent.Site.Name))
End If
Console.WriteLine(("Type of the component of the previously active designer: " + e.OldDesigner.RootComponentClassName))
End Sub
public void LinkActiveDesignerEvent(IDesignerEventService eventService)
{
// Registers an event handler for the ActiveDesignerChanged event.
eventService.ActiveDesignerChanged += new ActiveDesignerEventHandler(this.OnActiveDesignerEvent);
}
private void OnActiveDesignerEvent(object sender, ActiveDesignerEventArgs e)
{
// Displays changed designer information on the console.
if( e.NewDesigner.RootComponent.Site != null )
Console.WriteLine("Name of the component of the new active designer: "+e.NewDesigner.RootComponent.Site.Name);
Console.WriteLine("Type of the component of the new active designer: "+e.NewDesigner.RootComponentClassName);
if( e.OldDesigner.RootComponent.Site != null )
Console.WriteLine("Name of the component of the previously active designer: "+e.OldDesigner.RootComponent.Site.Name);
Console.WriteLine("Type of the component of the previously active designer: "+e.OldDesigner.RootComponentClassName);
}
public:
void LinkActiveDesignerEvent( IDesignerEventService^ eventService )
{
// Registers an event handler for the ActiveDesignerChanged event.
eventService->ActiveDesignerChanged += gcnew ActiveDesignerEventHandler( this, &MiscCompModSamples::ActiveDesignerEventHandlerExample::OnActiveDesignerEvent );
}
private:
void OnActiveDesignerEvent( Object^ /*sender*/, ActiveDesignerEventArgs^ e )
{
// Displays changed designer information on the console.
if ( e->NewDesigner->RootComponent->Site != nullptr )
{
Console::WriteLine( "Name of the component of the new active designer: {0}", e->NewDesigner->RootComponent->Site->Name );
}
Console::WriteLine( "Type of the component of the new active designer: {0}", e->NewDesigner->RootComponentClassName );
if ( e->OldDesigner->RootComponent->Site != nullptr )
{
Console::WriteLine( "Name of the component of the previously active designer: {0}", e->OldDesigner->RootComponent->Site->Name );
}
Console::WriteLine( "Type of the component of the previously active designer: {0}", e->OldDesigner->RootComponentClassName );
}
public void LinkActiveDesignerEvent(IDesignerEventService eventService)
{
// Registers an event handler for the ActiveDesignerChanged event.
eventService.add_ActiveDesignerChanged(new ActiveDesignerEventHandler(
this.OnActiveDesignerEvent));
} //LinkActiveDesignerEvent
private void OnActiveDesignerEvent(Object sender, ActiveDesignerEventArgs e)
{
// Displays changed designer information on the console.
if (e.get_NewDesigner().get_RootComponent().get_Site() != null) {
Console.WriteLine("Name of the component of the new active designer: "
+ e.get_NewDesigner().get_RootComponent().get_Site().get_Name());
}
Console.WriteLine("Type of the component of the new active designer: "
+ e.get_NewDesigner().get_RootComponentClassName());
if (e.get_OldDesigner().get_RootComponent().get_Site() != null) {
Console.WriteLine("Name of the component of the previously active"
+ " designer: " + e.get_OldDesigner().get_RootComponent().
get_Site().get_Name());
}
Console.WriteLine("Type of the component of the previously active "
+ " designer: " + e.get_OldDesigner().get_RootComponentClassName());
} //OnActiveDesignerEvent
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
System.ComponentModel.Design 命名空间
ActiveDesignerEventArgs 类
ActiveDesignerChanged