WebBrowser.DetachSink Methode

Definition

Gibt den in die CreateSink()-Methode eingefügten Ereignisbehandlungsclient vom zugrunde liegenden ActiveX-Steuerelement frei.

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

Beispiele

Im folgenden Codebeispiel wird die Verwendung dieser Methode in einer von WebBrowser abgeleiteten Klasse veranschaulicht, die die Standardereignisse WebBrowser mit dem NavigateError Ereignis aus der OLE-Schnittstelle DWebBrowserEvents2 ergänzt.

Das vollständige Codebeispiel finden Sie unter 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

Hinweise

Diese Methode ist nützlich, wenn Sie mit der OLE-Entwicklung mit dem nicht verwalteten WebBrowser ActiveX-Steuerelement vertraut sind und die Funktionalität des Windows Forms-Steuerelements WebBrowser erweitern möchten, bei dem es sich um einen verwalteten Wrapper für das ActiveX-Steuerelement handelt. Sie können diese Erweiterbarkeit verwenden, um Ereignisse aus dem ActiveX-Steuerelement zu implementieren, die nicht vom Wrappersteuerelement bereitgestellt werden.

Gilt für:

Weitere Informationen