共用方式為


WebBrowser.DetachSink 方法

定義

從基礎 ActiveX 控制項釋放 CreateSink() 方法中所連接的事件處理用戶端。

protected:
 override void DetachSink();
protected override void DetachSink ();
override this.DetachSink : unit -> unit
Protected Overrides Sub DetachSink ()

範例

下列程式代碼範例說明在衍生自 WebBrowser 的類別中使用這個方法,以從 OLE DWebBrowserEvents2 介面補充標準WebBrowser事件NavigateError

如需完整的程式碼範例,請參閱 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 控件實作事件。

適用於

另請參閱