WebBrowser.DetachSink Metodo

Definizione

Rilascia il client che gestisce gli eventi associato nel metodo CreateSink() dal controllo ActiveX sottostante.

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

Esempio

Nell'esempio di codice seguente viene illustrato l'uso di questo metodo in una classe derivata da WebBrowser che integra gli eventi standard WebBrowser con l'evento NavigateError dall'interfaccia OLE DWebBrowserEvents2 .

Per l'esempio di codice completo, vedere 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

Commenti

Questo metodo è utile se si ha familiarità con lo sviluppo OLE usando il controllo ActiveX non gestito WebBrowser e si desidera estendere la funzionalità del controllo Windows FormsWebBrowser, ovvero un wrapper gestito per il controllo ActiveX. È possibile usare questa estendibilità per implementare eventi dal controllo ActiveX non forniti dal controllo wrapper.

Si applica a

Vedi anche