WebBrowser.DetachSink 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从基础 ActiveX 控件中释放附加在 CreateSink() 方法中的事件处理客户端。
protected:
override void DetachSink();
protected override void DetachSink ();
override this.DetachSink : unit -> unit
Protected Overrides Sub DetachSink ()
示例
下面的代码示例演示如何在派生自 WebBrowser 的类中使用此方法,该类使用 NavigateError
OLE DWebBrowserEvents2
接口中的 事件来补充标准WebBrowser事件。
有关完整的代码示例,请参阅 CreateSink。
AxHost.ConnectionPointCookie cookie;
WebBrowser2EventHelper helper;
protected override void CreateSink()
{
base.CreateSink();
// Create an instance of the client that will handle the event
// and associate it with the underlying ActiveX control.
helper = new WebBrowser2EventHelper(this);
cookie = new AxHost.ConnectionPointCookie(
this.ActiveXInstance, helper, typeof(DWebBrowserEvents2));
}
protected override void DetachSink()
{
// Disconnect the client that handles the event
// from the underlying ActiveX control.
if (cookie != null)
{
cookie.Disconnect();
cookie = null;
}
base.DetachSink();
}
Private cookie As AxHost.ConnectionPointCookie
Private helper As WebBrowser2EventHelper
<PermissionSetAttribute(SecurityAction.LinkDemand, _
Name := "FullTrust")> Protected Overrides Sub CreateSink()
MyBase.CreateSink()
' Create an instance of the client that will handle the event
' and associate it with the underlying ActiveX control.
helper = New WebBrowser2EventHelper(Me)
cookie = New AxHost.ConnectionPointCookie( _
Me.ActiveXInstance, helper, GetType(DWebBrowserEvents2))
End Sub
<PermissionSetAttribute(SecurityAction.LinkDemand, _
Name := "FullTrust")> Protected Overrides Sub DetachSink()
' Disconnect the client that handles the event
' from the underlying ActiveX control.
If cookie IsNot Nothing Then
cookie.Disconnect()
cookie = Nothing
End If
MyBase.DetachSink()
End Sub
注解
如果你熟悉使用非托管 WebBrowser
ActiveX 控件进行 OLE 开发,并且想要扩展 Windows 窗体 WebBrowser 控件(ActiveX 控件的托管包装器)的功能,则此方法非常有用。 可以使用此扩展性来实现 ActiveX 控件中未由包装器控件提供的事件。