Maarten
Maarten

Reputation: 57

vb.net how to catch new window from dynamic webbrowser?

I have a tabbed browser and put a webbrowser behind the form, so it won't showup in the design or code and cannot call: Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow

This is how i load the form:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Try

        Dim tab As New TabPage
        Dim brws As New WebBrowser
        brws.ScriptErrorsSuppressed = True
        brws.Dock = DockStyle.Fill
        tab.Text = " New Tab"
        tab.Controls.Add(brws)
        Me.TabControl1.TabPages.Add(tab)
        Me.TabControl1.SelectedTab = tab
        brws.Navigate("")
    Catch ex As Exception

    End Try

End Sub

How can i catch the new window from my tabbed browser? I need it to load outgoing/external links to open in new windows and not in IE.

I have tried this but that will do nothing:

Private Sub WebBrowserNewWindow(ByVal sender As Object, ByVal e As System.EventArgs)
        MsgBox("catched the new window")
    End Sub

Upvotes: 0

Views: 2539

Answers (1)

Tom
Tom

Reputation: 3374

You need to add the line (after creating the control):

AddHandler brws.NewWindow, AddressOf WebBrowserNewWindow

for it to handle that event, see http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.newwindow(v=vs.110).aspx

Upvotes: 1

Related Questions