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
備註
如果您熟悉使用 Unmanaged WebBrowser
ActiveX 控制項的 OLE 開發,而且想要擴充Windows Forms WebBrowser 控制項的功能,這是ActiveX控制項的 Managed 包裝函式,這個方法會很有用。 您可以使用這個擴充性,從包裝函式控制項未提供的ActiveX控制項實作事件。