-
Jul 17th, 2009, 04:10 PM
#1
Thread Starter
Addicted Member
[RESOLVED] WebBrowser Tabs
Hi im New To VB , Dont Know If ive Posted This Thread In Right Selection
I wanna know How to Create Tabs in Web Browser To all Differenet Sites At The Same Time But I Need Someone To Tell Me What to Do in Dum Dum Terms Please thanks if anyone can Help Ive read All The Tab Control Posts Still no help lIke i Would be Thankful If SomeOne told me How to
Like What i Need To Do Then Code thanks for listening
-
Jul 17th, 2009, 04:21 PM
#2
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 17th, 2009, 05:31 PM
#3
Thread Starter
Addicted Member
Re: WebBrowser Tabs
nope that didnt work anyone else with tutorials on how to make tabs in dum dum terms :>
-
Jul 17th, 2009, 06:52 PM
#4
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 18th, 2009, 07:34 AM
#5
Thread Starter
Addicted Member
Re: WebBrowser Tabs
ive already been on that thread didnt understand what i had to do :> sorry if im a pain but i didnt understand it looked through the forum first
-
Jul 18th, 2009, 07:37 AM
#6
Re: WebBrowser Tabs
Can you explain what exactly is is that you don't understand... jmcilhinney's example is a pretty straightforward and comprehensive walkthrough.
-
Jul 18th, 2009, 08:13 AM
#7
Thread Starter
Addicted Member
Re: WebBrowser Tabs
everything like what i need to design first how to emulate the tabs what code i need to stick in and were to put it thats it really that thread didnt understand what i needed to do im kind of thick in written but been shown how to do something i pick it up really easyly
-
Jul 18th, 2009, 08:17 AM
#8
Re: WebBrowser Tabs
So are you able to create a web-browser that doesn't use tabs? I'm trying to understand whether you are trying to run before you can crawl. Is it the tabs bit that you cant understand or is it that you can't do any of it at the moment?
-
Jul 18th, 2009, 08:19 AM
#9
Thread Starter
Addicted Member
Re: WebBrowser Tabs
ive got the webrowser working without tabs just cant do the tabs i need someone to tell me how to do it simple steps :>
-
Jul 18th, 2009, 08:22 AM
#10
Re: WebBrowser Tabs
OK... do you understand how to create new controls at runtime?
-
Jul 18th, 2009, 08:24 AM
#11
Thread Starter
Addicted Member
Re: WebBrowser Tabs
i dont know about that can u help if i say no
-
Jul 18th, 2009, 08:31 AM
#12
Re: WebBrowser Tabs
to create a new control at runtime you just create a New instance of the control, set any properties you need to set and then add it to the parent control.
For example to create a new tab page and add it to the tabcontrol you can do something like this :
Code:
Dim X As New TabPage
X.Text = "My New Tab"
TabControl1.TabPages.Add(X)
So that will create a new tabpage.
You want to extend that by creating a new webbrowser control and adding that to your new TabPage (X) controls collection.
Try adding a webbrowser control to your new tabpage and see how you get on.
(jmcilhinney's example is a better one as he creates a new type of tab page which has a webbrowser control embedded into it, but this way is possibly simpler to understand for the beginner)
-
Jul 18th, 2009, 09:07 AM
#13
Thread Starter
Addicted Member
Re: WebBrowser Tabs
its doing me head in now , how do i create a new instance of control , How Do I Set the Properties here is my code
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate(ComboBox1.Text)
WebBrowser1.WebBrowserShortcutsEnabled = True
End Sub
Private Sub ComboBox1_KeyDown_(ByVal sender As Object, ByVal e As KeyEventArgs) Handles ComboBox1.KeyDown
If (e.KeyCode = Keys.Enter) Then
Navigate(ComboBox1.Text)
End If
End Sub
Private Sub WebBrowser1_Navigated(ByVal sender As Object, _
ByVal e As WebBrowserNavigatedEventArgs) _
Handles WebBrowser1.Navigated
ComboBox1.Text = WebBrowser1.Url.ToString()
End Sub
Private Sub Navigate(ByVal address As String)
If String.IsNullOrEmpty(address) Then Return
If address.Equals("about:blank") Then Return
If Not address.StartsWith("http://") And _
Not address.StartsWith("https://") Then
address = "http://" & address
End If
Try
WebBrowser1.Navigate(New Uri(address))
Catch ex As System.UriFormatException
Return
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.GoBack()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.GoForward()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
WebBrowser1.Refresh()
ProgressBar1.Increment(1)
If Timer1.Enabled = True Then
ProgressBar1.Value = 0
End If
If Timer2.Enabled = True Then
ProgressBar1.Value = 100
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
WebBrowser1.Stop()
If Timer1.Enabled = True Then
ProgressBar1.Value = 0
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.GoHome()
WebBrowser1.Navigate("sharewarez.sqweebs.com")
ProgressBar1.Increment(1)
If Timer2.Enabled = True Then
ProgressBar1.Value = 100
End If
End Sub
Private Function IsPopupWindow() As Boolean
On Error Resume Next
If WebBrowser1.Document.ActiveElement.TagName = "BODY" Or WebBrowser1.Document.ActiveElement.TagName = "IFRAME" Then
IsPopupWindow = True
Else
IsPopupWindow = True
End If
End Function
Private Sub ComboBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ProgressBar1.Increment(1)
If Timer1.Enabled = True Then
ProgressBar1.Value = 0
End If
If Timer2.Enabled = True Then
ProgressBar1.Value = 100
End If
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
ProgressBar1.Increment(1)
If Timer1.Enabled = True Then
ProgressBar1.Value = 0
End If
If Timer2.Enabled = True Then
ProgressBar1.Value = 100
End If
If Timer1.Enabled = True Then
ProgressBar1.Value = 0
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub TabPage1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim X As New TabPage
X.Text = "My New Tab"
TabControl1.TabPages.Add(X)
End Sub
End Class
-
Jul 18th, 2009, 09:15 AM
#14
Re: WebBrowser Tabs
OK - the first problem you have there is that your TabPage1_Click code isn't handling any event so it isn't going to fire unless you call it manually. It ought to be
Code:
Private Sub TabPage1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage1.Click
Dim X As New TabPage
X.Text = "My New Tab"
TabControl1.TabPages.Add(X)
End Sub
How do you set the properties? Well ' X.Text = "MyNewTab" ' is an example of setting the text property of your new control. Setting other properties is exactly the same.
-
Jul 18th, 2009, 09:20 AM
#15
Thread Starter
Addicted Member
Re: WebBrowser Tabs
sort of got it to work it opens a new tab but doesnt keep a different web page handled like so what do i put the X.text propertie as??
Be back in bit
-
Jul 18th, 2009, 09:35 AM
#16
Re: WebBrowser Tabs
Right OK I was trying to go one step at a time...
Firstly you havent created a new webbrowser control - you should do that in your tabpage1_click event after the code that makes your new tab. You apply the same principle as you followed for creating the new tab except you create a new webbrowser control instead of a tabpage, and you add it to your new tabpage (X) controls collection instead of the tabcontrol's tabpages collection.
After you've done that...
Looking at your code you have a set of buttons and a combo box to control navigation and they all reference WebBrowser1, but now that you have more than one browser control you need to get them to work on whichever webbrowser is selected.
To do that you can either declare a local variable to refrence the active webbrowser, ie declare a variable "Dim CurrentBrowser As WebBrowser" and when you change tab set CurrentBrowser = the webbrowser on the tab. The simplest way to do this (assuming that there is just a webbrowser control on each tab) is to do this :
Code:
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
CurrentBrowser = CType(sender, TabControl).SelectedTab.Controls(0)
End Sub
Then change all your current code in the buttons and combo box events to reference CurrentBrowser instead of WebBrowser1.
After that.. you'll need to hook up any events currently associated with webbrowser1 so that they will apply to your new webbrowser control that you've created for your new tab.
-
Jul 19th, 2009, 01:16 PM
#17
Thread Starter
Addicted Member
Re: WebBrowser Tabs
ryt well can you explain step 1 ?? please coz now when i click tabs it doesnt show new tab when debugging
-
Jul 19th, 2009, 01:20 PM
#18
Thread Starter
Addicted Member
Re: WebBrowser Tabs
the last message you just wrote about we need to create a second webbrowser do that step didnt understand understand how to embed 2 webbrowsers please
-
Jul 19th, 2009, 01:36 PM
#19
Re: WebBrowser Tabs
What I was saying is that you have events like this :
Code:
Private Sub WebBrowser1_Navigated(ByVal sender As Object, _
ByVal e As WebBrowserNavigatedEventArgs) _
Handles WebBrowser1.Navigated
ComboBox1.Text = WebBrowser1.Url.ToString()
End Sub
Which currently will fire when the Webbrowser1 has finished navigating to a URL. You will presumably want your new WebBrowser that you've just created to act in the same way.
In order to do this you need to call AddHandler to hook the existing routine you have already written, up to your new webbrowser control.
-
Jul 19th, 2009, 01:39 PM
#20
Thread Starter
Addicted Member
Re: WebBrowser Tabs
you dont get what i mean do u i mean were do i put the new web browser how do i add addhandler - please give example code and when you sed This yesterday Right OK I was trying to go one step at a time...
Firstly you havent created a new webbrowser control - you should do that in your tabpage1_click event after the code that makes your new tab. You apply the same principle as you followed for creating the new tab except you create a new webbrowser control instead of a tabpage, and you add it to your new tabpage (X) controls collection instead of the tabcontrol's tabpages collection.
After you've done that...
Looking at your code you have a set of buttons and a combo box to control navigation and they all reference WebBrowser1, but now that you have more than one browser control you need to get them to work on whichever webbrowser is selected.
To do that you can either declare a local variable to refrence the active webbrowser, ie declare a variable "Dim CurrentBrowser As WebBrowser" and when you change tab set CurrentBrowser = the webbrowser on the tab. The simplest way to do this (assuming that there is just a webbrowser control on each tab) is to do this :
Please Can We Go step By Step Again coz its really straining me head
-
Jul 19th, 2009, 01:42 PM
#21
Thread Starter
Addicted Member
Re: WebBrowser Tabs
can you not give me screen shots or can u add me on msn or something and show me what to do by screenshots :> would be a lot easyer
-
Jul 19th, 2009, 01:45 PM
#22
Re: WebBrowser Tabs
OK.. right I've shown how you create a new tabpage.. creating the new webbrowser control is exactly the same principle...
This is the code for creating the new tabpage :
Code:
Dim X As New TabPage
X.Text = "My New Tab"
TabControl1.TabPages.Add(X)
You now want to create a new webbrowser and add it to your new TabPage, so you want something like this :
Code:
Dim X As New TabPage
X.Text = "My New Tab"
TabControl1.TabPages.Add(X)
Dim Y as New WebBrowser
Y.Dock = DockStyle.Fill
X.Controls.Add(Y)
Last edited by keystone_paul; Jul 20th, 2009 at 01:40 AM.
-
Jul 19th, 2009, 02:01 PM
#23
Thread Starter
Addicted Member
Re: WebBrowser Tabs
ryt ive done what you just told me to do but when i deburg it it doesnt load up websites because webbrowser 2 is ontop of web browser 1 so now how do i add the addhandler to the 2 browser example code please bro
-
Jul 19th, 2009, 02:02 PM
#24
Thread Starter
Addicted Member
Re: WebBrowser Tabs
like This As You Was Saying earler Bro
Code:
What I was saying is that you have events like this :
Code:
Private Sub WebBrowser1_Navigated(ByVal sender As Object, _
ByVal e As WebBrowserNavigatedEventArgs) _
Handles WebBrowser1.Navigated
ComboBox1.Text = WebBrowser1.Url.ToString()
End SubWhich currently will fire when the Webbrowser1 has finished navigating to a URL. You will presumably want your new WebBrowser that you've just created to act in the same way.
In order to do this you need to call AddHandler to hook the existing routine you have already written, up to your new webbrowser control.
-
Jul 19th, 2009, 02:06 PM
#25
Re: WebBrowser Tabs
Um.. just spotted a mistake in my previous post - "MyWebBrowser" should be "Y" - copy and paste error but shouldnt cause the problem you are saying.
It certainly shouldn't be on top of webbrowser1... it should be on a separate tab.
can you post a screenshot - basically you should have two tab pages, each with one webbrowser each.
if that isn't the case can you paste your code here.
-
Jul 19th, 2009, 02:25 PM
#26
Thread Starter
Addicted Member
Re: WebBrowser Tabs
no its just not working for me is it web browser 2 sits ontop of my webbrowser 1 here is my code
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate(ComboBox1.Text)
WebBrowser1.WebBrowserShortcutsEnabled = True
End Sub
Private Sub ComboBox1_KeyDown_(ByVal sender As Object, ByVal e As KeyEventArgs) Handles ComboBox1.KeyDown
If (e.KeyCode = Keys.Enter) Then
Navigate(ComboBox1.Text)
End If
End Sub
Private Sub WebBrowser1_Navigated(ByVal sender As Object, _
ByVal e As WebBrowserNavigatedEventArgs) _
Handles WebBrowser1.Navigated
ComboBox1.Text = WebBrowser1.Url.ToString()
End Sub
Private Sub Navigate(ByVal address As String)
If String.IsNullOrEmpty(address) Then Return
If address.Equals("about:blank") Then Return
If Not address.StartsWith("http://") And _
Not address.StartsWith("https://") Then
address = "http://" & address
End If
Try
WebBrowser1.Navigate(New Uri(address))
Catch ex As System.UriFormatException
Return
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.GoBack()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.GoForward()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
WebBrowser1.Refresh()
ProgressBar1.Increment(1)
If Timer1.Enabled = True Then
ProgressBar1.Value = 0
End If
If Timer2.Enabled = True Then
ProgressBar1.Value = 100
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
WebBrowser1.Stop()
If Timer1.Enabled = True Then
ProgressBar1.Value = 0
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.GoHome()
WebBrowser1.Navigate("sharewarez.sqweebs.com")
ProgressBar1.Increment(1)
If Timer2.Enabled = True Then
ProgressBar1.Value = 100
End If
End Sub
Private Function IsPopupWindow() As Boolean
On Error Resume Next
If WebBrowser1.Document.ActiveElement.TagName = "BODY" Or WebBrowser1.Document.ActiveElement.TagName = "IFRAME" Then
IsPopupWindow = True
Else
IsPopupWindow = True
End If
End Function
Private Sub ComboBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ProgressBar1.Increment(1)
If Timer1.Enabled = True Then
ProgressBar1.Value = 0
End If
If Timer2.Enabled = True Then
ProgressBar1.Value = 100
End If
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
ProgressBar1.Increment(1)
If Timer1.Enabled = True Then
ProgressBar1.Value = 0
End If
If Timer2.Enabled = True Then
ProgressBar1.Value = 100
End If
If Timer1.Enabled = True Then
ProgressBar1.Value = 0
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub TabPage1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage1.Click
Dim X As New TabPage
X.Text = "Tabs "
TabControl1.TabPages.Add(X)
Dim Y As New WebBrowser
WebBrowser2.Dock = DockStyle.Fill
X.Controls.Add(Y)
End Sub
End Class
-
Jul 19th, 2009, 02:34 PM
#27
Re: WebBrowser Tabs
Where does WebBrowser2 come from?
That isn't the WebBrowser control that is created in code, it must be one you've had lying around from previous experimenting.
Note that I made a mistake in my code above and corrected it - this may have confused things slightly, but I don't think WebBrowser2 should be there at all.
-
Jul 19th, 2009, 02:41 PM
#28
Thread Starter
Addicted Member
Re: WebBrowser Tabs
so how do i create web browser 2 how am i supposed to create it tell me exactly what i need to click do add code this that and other and what need correcting thank you for not getting pissed off at me
-
Jul 19th, 2009, 02:45 PM
#29
Re: WebBrowser Tabs
The code I've given you creates the new webbrowser control, you don't do it yourself in the designer.
The whole point is you create them at runtime not at design time, because you just don't know how many tabs you will need.
Code:
1. Dim Y as New WebBrowser
2. MyWebBrowser.Dock = DockStyle.Fill
3. X.Controls.Add(Y)
Line 1 creates a new webbrowser but this doesn't exist on your form yet
Line 2 tells it to fill up all the available space when it gets added to a container
Line 3 attaches it to your new tabpage (X) and makes it visible to the world
-
Jul 19th, 2009, 02:59 PM
#30
Thread Starter
Addicted Member
Re: WebBrowser Tabs
yea its giving me error as MyWebBrowser.Dock
-
Jul 19th, 2009, 03:21 PM
#31
Re: WebBrowser Tabs
Originally Posted by pillhead2007
yea its giving me error as MyWebBrowser.Dock
What is the error exactly?
-
Jul 19th, 2009, 06:36 PM
#32
Thread Starter
Addicted Member
Re: WebBrowser Tabs
MyWebBrowser Not Declared
-
Jul 19th, 2009, 06:43 PM
#33
Thread Starter
Addicted Member
Re: WebBrowser Tabs
as soon as i get this tabbed thing ryt im gonna keep the code just in case :> lol
-
Jul 19th, 2009, 09:43 PM
#34
New Member
Re: WebBrowser Tabs
Argh, no offense to you but all this bad spelling gives me a headache.
Anyway, the error means that you haven't declared MyWebBrowser (but that's pretty much obvious). Basically you're trying to use MyWebBrowser without making one first.
I'm not exactly sure what keystone is trying to do, but I think by MyWebBrowser he/she means whatever the name of your WebBrowser is. In your case it seems to be WebBrowser1 or WebBrowser2 or something, I'm not really good at reading other people's code.
-
Jul 20th, 2009, 01:39 AM
#35
Re: WebBrowser Tabs
No it should be "Y" now MyWebBrowser or WebBrowser 2.
Sorry its my fault, I made the original copy and paste error (I was working on a similar problem for another poster at the same time).
I pointed this mistake out in post #25, and pointed out again in post #27 that the name needed changing. I've edited the original post to try and prevent any further confusion.
But then I compounded the error by copy and pasting the incorrect code from Pillhead's post without checking that the code was fixed.
To reitrate this code should be :
Code:
1. Dim Y as New WebBrowser
2. Y.Dock = DockStyle.Fill
3. X.Controls.Add(Y)
-
Jul 20th, 2009, 07:11 AM
#36
Thread Starter
Addicted Member
Re: WebBrowser Tabs
look at me code it is fixed but MyWebBrowser.Dock Still Error Check My Code
Code:
Private Sub TabPage1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage1.Click
Dim X As New TabPage
X.Text = "Tabs "
TabControl1.TabPages.Add(X)
Dim Y As New WebBrowser
MyWebBrowser.Dock = DockStyle.Fill
X.Controls.Add(Y)
End Sub
End Class
red highlighted is error
-
Jul 20th, 2009, 07:12 AM
#37
Thread Starter
Addicted Member
-
Jul 20th, 2009, 07:14 AM
#38
Thread Starter
Addicted Member
Re: WebBrowser Tabs
anyways ive done that what else have i got to do :>
-
Jul 20th, 2009, 07:24 AM
#39
Re: WebBrowser Tabs
OK so is that bit working now?
-
Jul 20th, 2009, 07:25 AM
#40
Thread Starter
Addicted Member
Re: WebBrowser Tabs
yea no error on runtime now :> thanks for beein patient with me whats next
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|