Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,247 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,212 people online right now. Registration is fast and FREE... Join Now!




How to make a tab browser

 
Reply to this topicStart new topic

How to make a tab browser, How to let my application respond to every tab user has selected

rakyomin
12 Oct, 2008 - 07:18 PM
Post #1

D.I.C Head
**

Joined: 12 Sep, 2008
Posts: 77


My Contributions
I am making a tab browser, I know how to get the first tab to navigate according to user's desired url.

There is a tab which contain a webbrowser control known as WebBrowser1 with a dockstyle.fill within the Tab Control.
My form is designed to appear as only one tab. User can choose to create a new tab from the MenuStrip Control.

Below is my code:

vb

Public Class frmWebSurfer

Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
WebBrowser1.Navigate(cbxUrl.Text)

End Sub


Private Sub BackToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackToolStripMenuItem.Click
WebBrowser1.GoBack()
End Sub

Private Sub ForwardToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ForwardToolStripMenuItem.Click
WebBrowser1.GoForward()
End Sub

Private Sub RefreshToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshToolStripMenuItem.Click
WebBrowser1.Refresh()

End Sub

Private Sub StopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopToolStripMenuItem.Click
WebBrowser1.Stop()
End Sub


Private Sub cbxUrl_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cbxUrl.KeyDown
If e.KeyCode = Keys.Enter Then
e.SuppressKeyPress = True
WebBrowser1.Navigate(cbxUrl.Text)
End If
End Sub

Private Sub NewTabToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewTabToolStripMenuItem.Click
'create a new tab
Dim newTabPage As New TabPage
Dim newWebBrowser As New WebBrowser

newTabPage.Text = "TabPage" & tabBrowserFace.TabPages.Count + 1
'add browser to the tab control
newTabPage.Controls.Add(newWebBrowser)
newWebBrowser.Dock = DockStyle.Fill
newWebBrowser.Navigate(cbxUrl.Text)
'add the new tab
Me.tabBrowserFace.Controls.Add(newTabPage)

End Sub
End Class


As you can see WebBrowser1.Navigate can only respond to tabpage1, but not subsequent page user chooses to click.
If I add newWebBrowser.Navigate(cbxUrl.Text) in btnGo.Click event it will only respond to new tabpages user created and not to the first tabpage upon the application opens. What should I write btnGo.Click so that default tabpage1 and subsequent user created tabpages will respond to user's desired url?
User is offlineProfile CardPM
+Quote Post

rakyomin
RE: How To Make A Tab Browser
12 Oct, 2008 - 07:53 PM
Post #2

D.I.C Head
**

Joined: 12 Sep, 2008
Posts: 77


My Contributions
I rewrote my btnGo.click event as below:

vb

Private newWebBrowser As WebBrowser


Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click

If tabBrowserFace.TabPages.Count = 0 Then
WebBrowser1.Navigate(cbxUrl.Text)
Else
newWebBrowser.Navigate(cbxUrl.Text)
End If


But VB.net gave error "Object reference not set to an instance of an object." which is not true.. because in NewTabToolStripMenuItem.Click event: there is a new instance created for WebBrowser..

User is offlineProfile CardPM
+Quote Post

rakyomin
RE: How To Make A Tab Browser
13 Oct, 2008 - 08:43 AM
Post #3

D.I.C Head
**

Joined: 12 Sep, 2008
Posts: 77


My Contributions
ok since no one replies, i managed to solve this issue.

for the benefit of others facing the same problem here is the code sample:

vb

CType(tabControl.SelectedTab.Controls.Item(0), WebBrowser).Navigate(cbxUrl.Text)


by changing the type of the item selected of the tab control to webbrowser, vb.net can recognise which tab is selected and act according to what user has input in the url text box.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 03:51AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month