Alex
Alex

Reputation: 1398

VB.NET TabControl Web Browser?

I'm a bit new to this, but I'm working on a web browser with tabbed browsing, however..

When a new tab is created, it creates a web browser in it - but I want a function called when the browser is finished loading. I can't create a private sub inside a function, So I am not sure what I should do. Any Ideas?

My Code:

Function addtab()
    Dim myTabPage As New TabPage()
    Dim theweb As New WebBrowser

    myTabPage.Text = "TabPage Test" & (TabControl1.TabPages.Count + 1)
    TabControl1.TabPages.Add(myTabPage)

    theweb.GoHome()
    theweb.Parent = myTabPage
    theweb.Visible = True
    theweb.Dock = DockStyle.Fill
    Return True
End Function

Thanks!

Upvotes: 0

Views: 4763

Answers (1)

Justin C
Justin C

Reputation: 777

Sounds like you want to create a new webBrowser object, dock it in the new tabPage you make and then have the webBrowser do something when it's finished loading, correct?

What about something like this...

Public Class Form1

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

Function addtab()
    Dim myTabPage As New TabPage()
    Dim theweb As New WebBrowser()
    AddHandler theweb.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf Run_Me_On_Load)
    myTabPage.Text = "TabPage Test" & (TabControl1.TabPages.Count + 1)
    TabControl1.TabPages.Add(myTabPage)
    theweb.Navigate("http://justinchoponis.com")
    theweb.Parent = myTabPage
    theweb.Visible = True
    theweb.Dock = DockStyle.Fill
    Return True
End Function


Public Sub Run_Me_On_Load(sender As Object, e As EventArgs)
    MessageBox.Show("Finished loading")
End Sub

End Class

Upvotes: 3

Related Questions