WebBrowser.DetachSink Méthode

Définition

Libère le client de gestion d’événements joint à la méthode CreateSink() du contrôle ActiveX sous-jacent.

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

Exemples

L’exemple de code suivant illustre l’utilisation de cette méthode dans une classe dérivée de WebBrowser ce qui complète les événements standard WebBrowser avec l’événement de l’interface NavigateError OLE DWebBrowserEvents2 .

Pour obtenir l’exemple de code complet, consultez 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

Remarques

Cette méthode est utile si vous connaissez le développement OLE à l’aide du contrôle ActiveX non managé WebBrowser et que vous souhaitez étendre les fonctionnalités du contrôle Windows FormsWebBrowser, qui est un wrapper managé pour le contrôle ActiveX. Vous pouvez utiliser cette extensibilité pour implémenter des événements à partir du contrôle ActiveX qui ne sont pas fournis par le contrôle wrapper.

S’applique à

Voir aussi