School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,344 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,566 people online right now. Registration is fast and FREE... Join Now!




How to make a Tabbed Webbrowser

 
Reply to this topicStart new topic

> How to make a Tabbed Webbrowser, This is with Visual Basic 2008

Rating  5
Malazar
Group Icon



post 4 Nov, 2008 - 02:00 PM
Post #1


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:
CODE
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:
CODE
   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:
CODE
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:
CODE
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:
CODE
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoForward()

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

CODE
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!!!
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

rakyomin
**



post 6 Nov, 2008 - 05:35 PM
Post #2
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
vb

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

vb

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.
Go to the top of the page
+Quote Post

Malazar
Group Icon



post 11 Nov, 2008 - 04:34 PM
Post #3
Thanks for the advice rakyomin. That really helped.
Go to the top of the page
+Quote Post

dcrew
*



post 11 Dec, 2008 - 04:12 PM
Post #4
wheres the go button..?
ive tried
CODE
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.
Go to the top of the page
+Quote Post

dcrew
*



post 12 Dec, 2008 - 10:18 AM
Post #5
anyone going to help or what?
Go to the top of the page
+Quote Post

dimre01
*



post 13 Jan, 2009 - 06:13 PM
Post #6
QUOTE(rakyomin @ 6 Nov, 2008 - 05: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
vb

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

vb

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 smile.gif
Go to the top of the page
+Quote Post

VizualXTC
*



post 9 Feb, 2009 - 08:29 PM
Post #7
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
Go to the top of the page
+Quote Post

RoCKetPEEKO
*



post 10 Feb, 2009 - 12:35 PM
Post #8
Can someone please post the go button?

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


Doesn't work sad.gif. Please tell me the right one!

- RoCKetPEEKO!
Go to the top of the page
+Quote Post

Vermiculus
*



post 27 Feb, 2009 - 06:19 PM
Post #9
How about you try to make a go button and tell us what you come up with?
Go to the top of the page
+Quote Post

cdwoods
*



post 6 Mar, 2009 - 01:11 PM
Post #10
CODE
        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.

Go to the top of the page
+Quote Post

mimrah
*



post 10 Mar, 2009 - 08:53 AM
Post #11
Nice tutorial, I would like to add a few functions,
The followin is for form load

CODE

        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,

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,

CODE

    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
Go to the top of the page
+Quote Post

timothyfleet
*



post 12 Mar, 2009 - 01:09 AM
Post #12
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)

CODE
    

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.


CODE


    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!
Go to the top of the page
+Quote Post

sgaggerj
*



post 13 Mar, 2009 - 11:20 AM
Post #13
QUOTE(timothyfleet @ 12 Mar, 2009 - 01:09 AM) *


CODE
    

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
CODE

TextBox1.Text = sender.Url.ToString()


or
CODE

TextBox1.Text = TabControl1.SelectedTab.Controls.Item(0).Url.ToString()
Go to the top of the page
+Quote Post

sgaggerj
*



post 13 Mar, 2009 - 11:26 AM
Post #14
QUOTE(dcrew @ 11 Dec, 2008 - 04:12 PM) *

wheres the go button..?
ive tried
CODE
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

CODE

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
Go to the top of the page
+Quote Post

ray36
*



post 14 Mar, 2009 - 05:12 PM
Post #15
QUOTE(timothyfleet @ 12 Mar, 2009 - 01: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)

CODE
    

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.


CODE


    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".
Go to the top of the page
+Quote Post

Moonbase
*



post 4 Apr, 2009 - 06:06 AM
Post #16
Hi, I am new to visual basic but i have done a few simple web browsers trying to get used to how the language works.

I am now trying to create a tabbed web browser. Most of the code is pretty simple and straight forward, but I have run into a problem that I can't seem to get worked out.

I am trying to get the url of the current tab to display in the textbox. I have searched the web and this site for how to do it and have tried the codes above but nothing seems to work. Maybe I have the code in the wrong place but I don't know.

CODE
    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        TextBox1.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString()
    End Sub


Please help me understand this!
Go to the top of the page
+Quote Post

Koodud
*



post 17 Apr, 2009 - 05:57 PM
Post #17
QUOTE(Malazar @ 4 Nov, 2008 - 02: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:
CODE
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:
CODE
   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:
CODE
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:
CODE
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:
CODE
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoForward()

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

CODE
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!!!

QUOTE
Wheres the code for add tab???? biggrin.gif
Go to the top of the page
+Quote Post

Mr Dylan
*



post 2 May, 2009 - 06:14 PM
Post #18
Hi everyone. I seemed to have found a solution for the tab renaming. It seems that VB was not recognizing "Private Sub WebBrowser_Navigated"

Because if you put the same code in a timer

CODE

Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - WebBrowser's Name"
            TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle


It updates the tab but also makes the browser jumpy.

Does anyone have a better solution?
Go to the top of the page
+Quote Post

sanchezman1234
*



post 25 Jul, 2009 - 10:10 AM
Post #19
QUOTE(Mr Dylan @ 2 May, 2009 - 06:14 PM) *

Hi everyone. I seemed to have found a solution for the tab renaming. It seems that VB was not recognizing "Private Sub WebBrowser_Navigated"

Because if you put the same code in a timer

CODE

Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - WebBrowser's Name"
            TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle


It updates the tab but also makes the browser jumpy.

Does anyone have a better solution?


Yes i do. after adding

AddHandler wb.Navigating, AddressOf wbNavigating
AddHandler wb.ProgressChanged, AddressOf WbProgressChanged
AddHandler wb.DocumentCompleted, AddressOf WbDocumentCompleted

to form1_load

i added

TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle

to WbDocumentCompleted
it only works for the first tab
Go to the top of the page
+Quote Post


Fast ReplyReply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/7/09 05:51PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month