I need help on my web browser

Cabose

Active member
Joined
Oct 18, 2006
Messages
39
Programming Experience
Beginner
I am making a Web Browser and i have it set up using tabs but i cant get it to display the url in the combo box or the Document Title in the Form Text or the tab text.

Here is my code of what i am doing.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] NewTabToolStripMenuItem_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] NewTabToolStripMenuItem.Click[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] wb [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] WebBrowser[/SIZE]
[SIZE=2]TabControl1.TabPages.Add(TabControl1.TabPages.Count + 1, [/SIZE][SIZE=2][COLOR=#800000]"Blank"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]TabControl1.TabPages.Item(1).Controls.Add(wb)[/SIZE]
[SIZE=2]wb.Width = TabControl1.Width - 6[/SIZE]
[SIZE=2]wb.Height = TabControl1.Height[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] btnGo_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] btnGo.Click[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] [COLOR=black]wb [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] [COLOR=black]WebBrowser[/COLOR][/SIZE]
[SIZE=2][COLOR=black]wb = TabControl1.SelectedTab.Controls.Item(0)[/COLOR][/SIZE]
[SIZE=2][COLOR=black]wb.Navigate(cboURL.Text)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
[/COLOR][/SIZE]

That is my code for making the new tab and navigating within the new browser but i dont know how to get all of that to show up when i go to the next page.

i tried using the code

VB.NET:
[SIZE=4][COLOR=#000000]If wb.IsBusy = False Then[/COLOR][/SIZE]
[SIZE=4][COLOR=#000000]cboURL.Text = wb.Url.ToString()[/COLOR][/SIZE]
[SIZE=4][COLOR=#000000]EndIf[/COLOR][/SIZE]

but this doesnt work it shows up what was loaded into the browser before hand and if i make it to where the statement is true nothing happens.

Please Help asap

Thanks,
Cabose

 
Make use of the DocumentCompleted event, a method handler you create for this can handle this event for all tabs browsers. When creating the new webbrowser and tabpage you can store a reference to the tabpage in the webbrowsers Tag property. Here is an example very similar to what you do, I set the tabpage text to be DocumentTitle when it completes loading. If you make one of the tabs browsers navigate elsewhere afterwards the tab text will automatically change to the new documenttitle because the event handler applies this.
VB.NET:
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnNew.Click
    Dim tp As New TabPage("Blank")
    Dim wb As New WebBrowser
    AddHandler wb.DocumentCompleted, AddressOf WebBrowsers_DocumentCompleted
    wb.Tag = tp
    wb.Dock = DockStyle.Fill
    tp.Controls.Add(wb)
    TabControl1.TabPages.Add(tp)
    TabControl1.SelectedTab = tp
    wb.GoHome()
End Sub
 
Private Sub WebBrowsers_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
    Dim wb As WebBrowser = DirectCast(sender, WebBrowser)
    Dim tp As TabPage = DirectCast(wb.Tag, TabPage)
    tp.Text = wb.DocumentTitle
End Sub
 
Back
Top