WebBrowser.DetachSink Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Släpper den händelsehanteringsklient som CreateSink() är kopplad till metoden från den underliggande ActiveX-kontrollen.
protected:
override void DetachSink();
protected override void DetachSink();
override this.DetachSink : unit -> unit
Protected Overrides Sub DetachSink ()
Exempel
Följande kodexempel illustrerar användningen av den här metoden i en klass som härleds från WebBrowser som kompletterar standardhändelserna WebBrowserNavigateError med händelsen från OLE-gränssnittet DWebBrowserEvents2 .
Det fullständiga kodexemplet finns i 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
Kommentarer
Den här metoden är användbar om du är bekant med OLE-utveckling med den ohanterade WebBrowser ActiveX-kontrollen och du vill utöka funktionerna i kontrollen Windows Forms WebBrowser, som är en hanterad omslutning för ActiveX-kontrollen. Du kan använda den här utökningsbarheten för att implementera händelser från ActiveX-kontrollen som inte tillhandahålls av omslutningskontrollen.