WebBrowser.DetachSink メソッド

定義

基になる ActiveX コントロールの CreateSink() メソッドでアタッチされたイベント処理クライアントを解放します。

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

次のコード例は、OLE DWebBrowserEvents2 インターフェイスからのイベントで標準WebBrowserイベントを補完する派生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

注釈

このメソッドは、アンマネージ WebBrowser ActiveX コントロールを使用した OLE 開発に慣れている場合に、ActiveX コントロールのマネージド ラッパーであるWindows フォーム WebBrowser コントロールの機能を拡張する場合に便利です。 この機能拡張を使用すると、ラッパー コントロールによって提供されないActiveX コントロールのイベントを実装できます。

適用対象

こちらもご覧ください