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!
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:
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:
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.
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:
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
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
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?
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?
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
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".
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
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:
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: