• (3 Pages)
  • +
  • 1
  • 2
  • 3

How to make a Tabbed Webbrowser This is with Visual Basic 2008 Rate Topic: ***** 3 Votes

#1 Malazar  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 02-November 08

Post icon  Posted 04 November 2008 - 03:00 PM

Ok so this is my very first tutorial and I hope you like it. I am using Microsoft Visual Basic 2008. Just google it. I don't know if it works for Visual Basic 6.0 so bear with me.

1) The first thing you are gonna need is a tab control. Place this anywhere you would like but leave some room at the top or bottom for our URL function such as GO, Stop and Refresh.

2) Next you will need some buttons but if its okay with you I would like us to use a ToolStrip.

3) Put this near the top and add 2 buttons first of all. Then A Textbox and 5 more buttons.

4) Now what your gonna wanna do is either change the display type to text if you don't have images for it otherwise put an image for it.

5) Okay change the caption for the first button to Back, the second button to Forward, the third to GO!, the forth to Stop, the fifth one to Refresh, the sixth to Add Tab, then the last one to Remove Tab. You can name these whatever you like bu I am gonna keep it simple like this.

6) Now go into the declarations area of the coding and put this:
Dim i As Integer = 1

What this means is that i will be used as an integer.

7) Okay now go into form load and put this:
   Dim Browse As New WebBrowser
		TabControl1.TabPages.Add(1, "Page" & i)
		TabControl1.SelectTab(1 - 1)
		Browse.Name = "wb"
		Browse.Dock = DockStyle.Fill
		TabControl1.SelectedTab.Controls.Add(Browse)
		i = i + 1

Copy this into the add tab as well.
All this means is that the tab will add a tab page called page. The dock part just means it will fill the entire tab control. It will also open a tab when the program loads

8) Now go into the coding for the remove tab button it should look like this:
 TabControl1.TabPages.RemoveAt(TabControl1.SelectedIndex)
		TabControl1.SelectTab(TabControl1.TabPages.Count - 1)
		i = i - 1


9) Now go into the coding for the Back button it should look like this:
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoBack()

What this means is that the Control type will be for the tab control, it will be doing this on the selected tab, and the cotrols for the item webbrowser will be GO back.

10)For the forward button, stop button and, refresh button change it to these respectivly:
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoForward()

CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Stop()

CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Refresh()

There you go That is a Basic Tabbed Webbrowser. I am sorry I do not have images to help with this but I cannot save it as an image file. Sorry Guys!!!

Is This A Good Question/Topic? 2
  • +

Replies To: How to make a Tabbed Webbrowser

#2 rakyomin  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 77
  • Joined: 12-September 08

Posted 06 November 2008 - 06:35 PM

Another great tutorial related to browser making with vb.net

I would like to share some of my codes here.

The tabpages above will create tabpage 1, tabpage 2 if a new tab is added.

Instead of using tabpage 1/2/3 to identify the tabs, you can use the webbrowser.documenttitle to update the text property of your selected tab.

On the event navigated of your webbrowser control use this code
Private Sub WebBrowser_Navigated(ByVal sender As Object, ByVal e As WebBrowserNavigatedEventArgs)
        Me.Text = CType(TabCtrlWebWizard.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - WebBrowser's Name"
               TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle
            End Sub



when you are trying to access a site your form title and your tabpage text will change to those navigated site's document title.
for example you are surfing google, your tab page text and form title will show Google

Next implement the same code in your webbrowser document completed event

Private Sub WebBrowser_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
'your url text box will show the actual url of the page after the page is fully loaded        
cbxUrl.Text = e.Url.ToString
                Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - Webbrowser's name"
        TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle

    End Sub



documentcompleted event will raise once your page is fully loaded.
Was This Post Helpful? 0
  • +
  • -

#3 Malazar  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 02-November 08

Posted 11 November 2008 - 05:34 PM

Thanks for the advice rakyomin. That really helped.
Was This Post Helpful? 0
  • +
  • -

#4 dcrew  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-December 08

Posted 11 December 2008 - 05:12 PM

wheres the go button..?
ive tried
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(ToolStripComboBox1.Text)

but it didn't work, can anyone help me.. you never put the code for the go button.
Was This Post Helpful? 0
  • +
  • -

#5 dcrew  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-December 08

Posted 12 December 2008 - 11:18 AM

anyone going to help or what?
Was This Post Helpful? 0
  • +
  • -

#6 dimre01  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 13-January 09

Posted 13 January 2009 - 07:13 PM

View Postrakyomin, on 6 Nov, 2008 - 05:35 PM, said:

Another great tutorial related to browser making with vb.net

I would like to share some of my codes here.

The tabpages above will create tabpage 1, tabpage 2 if a new tab is added.

Instead of using tabpage 1/2/3 to identify the tabs, you can use the webbrowser.documenttitle to update the text property of your selected tab.

On the event navigated of your webbrowser control use this code
Private Sub WebBrowser_Navigated(ByVal sender As Object, ByVal e As WebBrowserNavigatedEventArgs)
        Me.Text = CType(TabCtrlWebWizard.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - WebBrowser's Name"
               TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle
            End Sub



when you are trying to access a site your form title and your tabpage text will change to those navigated site's document title.
for example you are surfing google, your tab page text and form title will show Google

Next implement the same code in your webbrowser document completed event

Private Sub WebBrowser_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
'your url text box will show the actual url of the page after the page is fully loaded        
cbxUrl.Text = e.Url.ToString
                Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - Webbrowser's name"
        TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle

    End Sub



documentcompleted event will raise once your page is fully loaded.




Hey rakyomin, I copied+pasted the code that you provided in the correct events. However when I try to build my project, I get two errors:

Error 1: Name 'cbxurl' is not declared

Error 2: Name 'TabCtrlWebWizard' is not declared

Is there any alternative way to fix this?
Thanks :)
Was This Post Helpful? 0
  • +
  • -

#7 VizualXTC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-February 09

Posted 09 February 2009 - 09:29 PM

As far as I can see it. Your first error can be fixed by changing "cbxURL" to whatever you named your URL textbox. If you never changed the name of it, it will be Textbox1.

As for your error 2, I don't know. I am actually having the same problem. I was thinking that I was supposed to change "TabCtrlWebWizard" to Tabcontrol2 (Since that is my Tabcontrol name) but in doing so, it took away the error, but did not perform the desired function.

If anyone can help with either error, please explain. Thanks
Was This Post Helpful? 0
  • +
  • -

#8 RoCKetPEEKO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-February 09

Posted 10 February 2009 - 01:35 PM

Can someone please post the go button?

CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(ComboBox1.Text)


Doesn't work :(. Please tell me the right one!

- RoCKetPEEKO!
Was This Post Helpful? 0
  • +
  • -

#9 Vermiculus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 314
  • Joined: 26-February 09

Posted 27 February 2009 - 07:19 PM

How about you try to make a go button and tell us what you come up with?
Was This Post Helpful? 0
  • +
  • -

#10 cdwoods  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-March 09

Posted 06 March 2009 - 02:11 PM

		CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(txturl.Text) 


i managed to get it to work using this code, however you will need to change the 'txturl' to whatever you have called the textbox you created earlier.
Was This Post Helpful? 0
  • +
  • -

#11 mimrah  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 08-March 09

Posted 10 March 2009 - 09:53 AM

Nice tutorial, I would like to add a few functions,
The followin is for form load

		If i = 0 Then
			i = 1
		End If
		If i < 0 Then
			i = 1
		End If
		Dim Browse As New ExtendedWebBrowser
		Browse.Name = "b1"
		Browse.Dock = DockStyle.Fill
		Dim wb As New ExtendedWebBrowser
		AddHandler Browse.DocumentCompleted, AddressOf Browse_done
		AddHandler Browse.ProgressChanged, AddressOf Browse_pro
		AddHandler Browse.StatusTextChanged, AddressOf Browse_status
		TabControl1.TabPages.Add(i, "Tab Page " & i)
		TabControl1.SelectTab(i)
		TabControl1.SelectedTab.Controls.Add(Browse)
		CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(My.Settings.Tabs)
		i = i + 1



If you want a progress bar, add a progressbar to the form and write the following code,

	Private Sub Browse_pro(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserProgressChangedEventArgs)
		Dim CurProg As Double
		Dim MaxProg As Double
		CurProg = e.CurrentProgress
		MaxProg = e.MaximumProgress
		progressbar1.Value = (CurProg / MaxProg) * 100
	End Sub



If you want a status bar use the following after adding a label to your form,

	Private Sub Browse_status(ByVal sender As Object, ByVal e As System.EventArgs)
		label1.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).StatusText
	End Sub


Was This Post Helpful? 0
  • +
  • -

#12 timothyfleet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-March 09

Posted 12 March 2009 - 02:09 AM

Hey, thanks for the "Adding tabs with browser window" script! Big help. but I am having a problem that i cant for the life of me figure out.

I made a browser like you have your code and its awesome but i want to reference the browser name so that i can add script to it, I am calling the new browser window "wb" cause that's what it gets named in your script. here is my code. (it labels the tab, the window, and changes the URL text field)

	 

 Private Sub wb_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles wb.Navigated
		TextBox1.Text = wb.Url.ToString()
		Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - My Browser"
		TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle

	End Sub




now the problem is that is wont let me build/test my project because "wb" is not defined, it dose not exists as far as VB is concerned.
I have tried changing "wb" to all kinds of things like "WebBrowser" and "Browse", but nothing will work. it always says that it the name doe snot exists.

Just for referance, here is the code that creates the tab with the browser window in it. it works fine.



	Dim Browse As New WebBrowser
		TabControl1.TabPages.Add(1, "Blank")
		TabControl1.SelectTab(i - 1)
		Browse.Name = "wb"
		Browse.Dock = DockStyle.Fill
		TabControl1.SelectedTab.Controls.Add(Browse)
		i = i + 1




It says "Browse.Name = "wb"" so thats why im trying to call it "wb". I inserted a WebBrowser on the form named wb and then tried to run it and it worked, it labeled the window, tab, and changed the URL field. So i know that the script works. Please help me, I know you guys can solve this, I'm really new at this.

So my final question is... What should I call the browser instead of "wb" when I am referring to it in the first script I posted above?

Thank you so much!
Was This Post Helpful? 0
  • +
  • -

#13 sgaggerj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-March 09

Posted 13 March 2009 - 12:20 PM

View Posttimothyfleet, on 12 Mar, 2009 - 01:09 AM, said:

	 

 Private Sub wb_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles wb.Navigated
		TextBox1.Text = wb.Url.ToString()
		Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - My Browser"
		TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle

	End Sub




It says "Browse.Name = "wb"" so thats why im trying to call it "wb". I inserted a WebBrowser on the form named wb and then tried to run it and it worked, it labeled the window, tab, and changed the URL field. So i know that the script works. Please help me, I know you guys can solve this, I'm really new at this.

So my final question is... What should I call the browser instead of "wb" when I am referring to it in the first script I posted above?

Thank you so much!



try
TextBox1.Text = sender.Url.ToString()



or
TextBox1.Text = TabControl1.SelectedTab.Controls.Item(0).Url.ToString()


Was This Post Helpful? 0
  • +
  • -

#14 sgaggerj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-March 09

Posted 13 March 2009 - 12:26 PM

View Postdcrew, on 11 Dec, 2008 - 04:12 PM, said:

wheres the go button..?
ive tried
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(ToolStripComboBox1.Text)

but it didn't work, can anyone help me.. you never put the code for the go button.


That code needs to go in the handler for your 'Go' button

if your Go button is named GoButton then

Private Sub GoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GoButton.Click
		CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(ToolStripComboBox1.Text)
End Sub


Was This Post Helpful? 0
  • +
  • -

#15 ray36  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-December 08

Posted 14 March 2009 - 06:12 PM

View Posttimothyfleet, on 12 Mar, 2009 - 01:09 AM, said:

Hey, thanks for the "Adding tabs with browser window" script! Big help. but I am having a problem that i cant for the life of me figure out.

I made a browser like you have your code and its awesome but i want to reference the browser name so that i can add script to it, I am calling the new browser window "wb" cause that's what it gets named in your script. here is my code. (it labels the tab, the window, and changes the URL text field)

	 

 Private Sub wb_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles wb.Navigated
		TextBox1.Text = wb.Url.ToString()
		Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - My Browser"
		TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle

	End Sub




now the problem is that is wont let me build/test my project because "wb" is not defined, it dose not exists as far as VB is concerned.
I have tried changing "wb" to all kinds of things like "WebBrowser" and "Browse", but nothing will work. it always says that it the name doe snot exists.

Just for referance, here is the code that creates the tab with the browser window in it. it works fine.



	Dim Browse As New WebBrowser
		TabControl1.TabPages.Add(1, "Blank")
		TabControl1.SelectTab(i - 1)
		Browse.Name = "wb"
		Browse.Dock = DockStyle.Fill
		TabControl1.SelectedTab.Controls.Add(Browse)
		i = i + 1




It says "Browse.Name = "wb"" so thats why im trying to call it "wb". I inserted a WebBrowser on the form named wb and then tried to run it and it worked, it labeled the window, tab, and changed the URL field. So i know that the script works. Please help me, I know you guys can solve this, I'm really new at this.

So my final question is... What should I call the browser instead of "wb" when I am referring to it in the first script I posted above?

Thank you so much!

You must add an event handler to it using "AddHandler".
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3