|
-
May 18th, 2010, 05:18 PM
#1
VB6 - Dynamic Tabbed Web Browser
This bit of code will dynamically add a Tab which
contains "its own" WebBrowser instance.
On your form you need:
- CommandButton named cbAddTab
- SSTab control named SSTab1, with default Tabs = 3
- WebBrowser control named WB1, placed on Tab 0, Index set to 0
Code:
' in declarations
Public nnTABS As Integer
' the sub
Private Sub cbAddTab_Click()
With SSTab1
' 1. first time it is clicked - sets up the controls
If nnTABs = 0 Then
nnTABs = nnTABs + 1
.Visible = True
.Top = 4500
.Left = 5500
.Width = 10000
.Height = 7000
.Tabs = 1
.TabsPerRow = 10
.TabMaxWidth = 1000
With WB1(0)
.Top = 1000
.Left = 500
.Height = 5500
.Width = 9000
.Visible = True
.Navigate2 "cme.com"
End With
' 2 subsequent clicks -- adds new tab and browser instance
ElseIf nnTABs > 0 Then
nnTABs = nnTABs + 1
With SSTab1
.Tabs = nnTABs
.Tab = nnTABs - 1
End With
Load WB1(nnTABs - 1)
With WB1(nnTABs - 1)
.Container = SSTab1
.Top = 1000
.Left = 500
.Height = 5500
.Width = 9000
.Visible = True
If nnTABs = 2 Then
.Navigate2 "yahoo.com"
ElseIf nnTABs = 3 Then
.Navigate2 "google.com"
ElseIf nnTABs = 4 Then
.Navigate2 "vbforums.com"
End If
End With
End If
End With
End Sub
A few comments are in order
- I hardwired the URLs (highlighted in blue) -- you'll probably want to make your app smarter
- I only defined things up to 4 tabs, so you might want to do more
- When cbAddTab is clicked first time, only 1 Tab appears
- With each subsequent click, a new tab is added with its own browser
- At any time you can click an extisting tab and it will show its browser
- Natch, you'll want to adapt .Top, .Left, etc to suit your needs
It is only a prototype. Much improvement is probably in order.
Feel free to comment.
Spoo
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
|