hi all .could any one show me how i can create dynamic tabs like firfox browser tabs. So when i press the + sign it creates a new tab with new browser controle there .Looking forward for reply.Thanks
Printable View
hi all .could any one show me how i can create dynamic tabs like firfox browser tabs. So when i press the + sign it creates a new tab with new browser controle there .Looking forward for reply.Thanks
I suppose that'd depend on what tab control you're using, or if you want to use one at all. You could easily make a command button control array to do this.
What is the problem, exactly?
Sure, create a command button(cmdTab), set the index to zero. Have another command button(cmdNewTab), set it's caption to +.
In the cmdNewTab_Click event:
I offer this, as they support the graphical Style, so you can use your own images for your tabs, so they look however you like!Code:Dim lGap As Long
Load cmdTab(cmdTab.Count)
lGap = 45 '45 twips is typically 3 pixels
cmdTab(cmdTab.UBound).Left = cmdTab(cmdTab.UBound - 1).Left + cmdTab(cmdTab.UBound).Width + lGap
cmdTab(cmdTab.UBound).Visible = True
Thanks for your help. But how to make dynamic tabs the code you show above only makes buttons !!
Tony
Maybe something like this ...
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
A few comments are in orderCode:' 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
- 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
- At any time you can click an extisting tab and it will show it's "own" browser
- Natch, you'll want to adapt .Top, .Left, etc to suit your needs
BTW, I actually tested this, and it works !!
Hopefully this will get you started.
Spoo
Many thanks spoo it worked well .But i want to load html files from a listbox when i click listbox items. could you show me how i can load these html urls in diffrent tabs when clicked on them ?
Furthermore, how to add listbox item value beside tab numbers so i know which tab belongs to what item in listbox and lastly how to close a perticuler tab ?Code:Private Sub List1_Click()
Form1.WebBrowser1.Navigate App.Path & "/" & List2.List(List1.ListIndex)
End Sub
Tony
Those seem doable.
Could you post a screenshot of your ListBox
Spoo
Thanks for your reply.one of the listbox in the right side has the html file path like /htmls/sport.html
and the other listbox has the name like "sport activity".So when i click on sport activity it should load /htmls/sport.html into an empty tab if the no empty tab exist make new one ...
Tony
See if this works for you
On your form you'll need:
- CommandButton named cbAddTab
- ListBox named List1 << new
- SSTab control named SSTab1, with default Tabs = 3
- WebBrowser control named WB1, placed on Tab 0, Index set to 0
- CommandButton named cbQuit, placed on Tab 0, Index set to 0 << new
A few comments:Code:' 1. in declarations
Public nnTABS As Integer
' 2. the initial load sub
Private Sub cbAddTab_Click()
With List1
.Top = 4500
.Left = 4000
.Height = 1000
.Width = 1300
.Visible = True
.AddItem "cme.com", 0
.AddItem "yahoo.com", 1
.AddItem "google.com", 2
.AddItem "vbforums.com", 3
End With
With SSTab1
If nnTABs = 0 Then
.Visible = True
.Top = 4500
.Left = 5500
.Width = 10000
.Height = 7000
.Tabs = 1
.TabsPerRow = 10
.TabMaxWidth = 1000
End If
End With
End Sub
' 3. click sub
Private Sub List1_Click()
'
' populate SSTab1, WB1(nnTABs)
'
With List1
v1 = .ListIndex
v2 = .List(v1)
nnTABs = nnTABs + 1
' Tab
With SSTab1
.Tabs = nnTABs
.Tab = nnTABs - 1
.Caption = Left(v2, InStr(v2, ".") - 1)
End With
' WB1
If nnTABs > 1 Then
Load WB1(nnTABs - 1)
End If
With WB1(nnTABs - 1)
.Container = SSTab1
.Top = 1000
.Left = 500
.Height = 5500
.Width = 9000
.Visible = True
.StatusBar = True
.MenuBar = True
.Navigate2 v2
End With
' cbQuit
If nnTABs > 1 Then
Load cbQuit(nnTABs - 1)
End If
With cbQuit(nnTABs - 1)
.Container = SSTab1
.Top = 500
.Left = 500
.Height = 300
.Width = 900
.Visible = True
End With
End With
End Sub
' 4. quit sub
Private Sub cbQuit_Click(Index As Integer)
'
' NOTE: only quits if on LAST tab
'
' last tab when only 1 tab
If nnTABs = 1 Then
nnTABs = 0
WB1(0).Visible = False
' last tab when >1 tabs
ElseIf nnTABs > 1 And Index = nnTABs - 1 Then
With WB1(nnTABs - 1)
.Stop
End With
If nnTABs > 1 Then
Unload WB1(nnTABs - 1)
Unload cbQuit(nnTABs - 1)
nnTABs = nnTABs - 1
With SSTab1
.Tabs = nnTABs
.Tab = nnTABs - 1
End With
End If
End If
End Sub
- Code in sub cbAddTab has changed (it only loads the List and SSTab)
- I hard-wired the URLs in the ListBox. You will need code to populate it
- You can click them in any order to add to the set of tabs
- Tab name is derived from just looking for the 1st "." in the string
- Quit button only works if it is the LAST tab... it will "remove" the Tab
You are kinda pushing my knowledge-base here.
There well may be better ways to do this, but at least this is a start.
Below is a cropped image to give you an idea of how this will look
EDIT:
Ha! You snuck in a post while I was composing.
Well, this should still serve as a starting point for you
Spoo
.
Many thanks spoo. i tried your code but when i click the listbox i get this error:
pointing at this line:Quote:
run-time error '438':
object doesn't support this property or method
.Container = SSTab1
Tony
Hmm.. it works fine for me.
A few questions..
- Which line did it occur on? (that line appears twice, for WB1 and for cbQuit)
- Is the name of your SSTab SSTab1?
- Did you copy my code directly, or did you adapt it?
Spoo
The error occur on inside WB1 List1_Click.
The name of SSTab is SSTab1.
I didn't use your new cbAddTab as i have another code to populate listbox so i used your old cbAddTab code. I even made new project and tried to use all your updated code but unfortunelty i get error in your updated code for cbAddTab too! The error :
pointing at :Quote:
Compile error:
Method or data memmber not found
Quote:
.Visible = True
I used the following code commenting out the cbQuit part so now the application works well but only problem that i can't close any tabs!! If i keep that cbQuit part i keep getting
pointing at this line:Quote:
run-time error '438':
object doesn't support this property or method
I hope you help me fix the quit button so i be able to close tabs.Quote:
.Container = SSTab1
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 = 2000
.Height = 5000
.Tabs = 1
.TabsPerRow = 10
.TabMaxWidth = 700
With WB1(0)
.Top = 500
.Left = 100
.Height = 4300
.Width = 5500
.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 = 500
.Left = 100
.Height = 4300
.Width = 5500
.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
Private Sub List1_Click()
'
' populate SSTab1, WB1(nnTABs)
'
With List2
If Option1.Value = True Then
v1 = List1.ListIndex
Else
v1 = List1.ListIndex
End If
v2 = .List(v1)
nnTABS = nnTABS + 1
' Tab
With SSTab1
.Tabs = nnTABS
.Tab = nnTABS - 1
If Option1.Value = True Then
.Caption = Left(v2, InStr(v2, ".") - 1)
Else
.Caption = List1.List(List1.ListIndex) & ":" & List1.ListIndex
End If
End With
' WB1
If nnTABS > 1 Then
Load WB1(nnTABS - 1)
End If
With Form1.WB1(nnTABS - 1)
.Container = SSTab1
'.Top = 1000
'.Left = 500
'.Height = 5500
'.Width = 9000
.Top = 1500
.Left = 100
.Height = 4300
.Width = 5500
.Visible = True
.StatusBar = True
.MenuBar = True
If Option1.Value = True Then
'MsgBox "wow"
.Navigate2 App.Path & "/" & "singers/" & v2
Else
.Navigate2 App.Path & "/" & v2
End If
End With
' cbQuit
If nnTABS > 1 Then
Load cbQuit(nnTABS - 1)
End If
'With cbQuit(nnTABS - 1)
' .Container = SSTab1
' .Top = 500
' .Left = 500
'.Height = 300
'.Width = 900
'.Visible = True
'End With
End With
End Sub
' 4. quit sub
Private Sub cbQuit_Click(Index As Integer)
'
' NOTE: only quits if on LAST tab
'
' last tab when only 1 tab
If nnTABS = 1 Then
nnTABS = 0
WB1(0).Visible = False
' last tab when >1 tabs
ElseIf nnTABS > 1 And Index = nnTABS - 1 Then
With WB1(nnTABS - 1)
.Stop
End With
If nnTABS > 1 Then
Unload WB1(nnTABS - 1)
Unload cbQuit(nnTABS - 1)
nnTABS = nnTABS - 1
With SSTab1
.Tabs = nnTABS
.Tab = nnTABS - 1
End With
End If
End If
End Sub
Tony
OK, we have two unresolved issues here:
- Getting my demo project to work for you
- Integrating the demo's concepts into your actual app
I think it will be easier if we tackle these 1-by-1,
so if I may, let us begin with the first one.
Below are two images regarding my demo project
- image-1 (on left) is Design Mode
- image-2 (on right) is after you click cbAddTab
Design Mode
First, let's make you have the controls set up as I envisioned.
To recap from post #8, the components are (see image-1):
- CommandButton named cbAddTab, Caption = AddTab
- ListBox named List1, Visible = False
- SSTab control named SSTab1, with default Tabs = 3, Visible = False
- WebBrowser control named WB1, placed on Tab 0, Index set to 0
- CommandButton named cbQuit, placed on Tab 0, Index set to 0
Note: there is nothing on Tab2 or Tab3
Run Time
Now, let me describe how the app will (should) run.
- Launch App - all you should see is cbAddTab
- Click cbAddTab - (see image-2) - all you should see is List1 and SSTab1 (which will have nothing on it yet).
- Click any item on List1 - 1st tab (Tab0) will "get" renamed, and its own cbQuit and WB1 will appear.
- Click another item on List1 - 2nd tab (Tab1) will likewise "get" renamed, and its own cbQuit and WB1 will appear.
I hope I'm not beating this to death, but I think it would
be instructive for you to see the basic concept in action.
Did you set up your test "new project" as described?
Can you now get it to work?
Spoo
.
Tony
Now let me briefly deal with part 2 - your modifications.
I see one possible problem in the following code frag:
The reason you get the error is that on the preceding statement,Code:Private Sub List1_Click()
' ...
With Form1.WB1(nnTABS - 1) ' << this is the problem
.Container = SSTab1 ' << you get error here
you have changed the reference of WB1().
- you have it as Form1.WB1(), which means you have Form1 as the
container. Hence, the subsequent statement is in conflict with this, and
you accordingly get the error.- WB1() should not be on the form, but rather on the SSTab control
This tells me that you have apparently modified the approach that I
tried to delineate in my prior post #12. Not that there is anything wrong
with that, but as you have now "branched out on your own", there
may be such unintended consequences.
Spoo
Many Many thanks for your nice explanation. Unfortunetly i even couldn't run your demo project !! When i click the cbAddTab i get the following error again:
pointing at :Quote:
Compile error:
Method or data memmber not found
I copy and paste your exact code and placed all the controles as the way you explained but still i get the above error so i uploaded the demo project so you be able to look at it.Quote:
Quote:
.Visible = True
Regarding Part 2 my modification i changed With Form1.WB1(nnTABS - 1) to WB1(nnTABS - 1) and got this error now :
pointing at in List1_Click :Quote:
run-time error '438'
object doesn't support this property or method
Quote:
With cbQuit(nnTABS - 1)
.Container = SSTab1 ===> pointing at here
part 2 - my modifications code.
Code:Private Sub List1_Click()
'
' populate SSTab1, WB1(nnTABs)
'
With List2
If Option1.Value = True Then
v1 = List1.ListIndex
Else
v1 = List1.ListIndex
End If
v2 = .List(v1)
nnTABS = nnTABS + 1
' Tab
With SSTab1
.Tabs = nnTABS
.Tab = nnTABS - 1
If Option1.Value = True Then
.Caption = Left(v2, InStr(v2, ".") - 1)
Else
.Caption = List1.List(List1.ListIndex) & ":" & List1.ListIndex
End If
End With
' WB1
If nnTABS > 1 Then
Load WB1(nnTABS - 1)
End If
With WB1(nnTABS - 1)
.Container = SSTab1
'.Top = 1000
'.Left = 500
'.Height = 5500
'.Width = 9000
.Top = 1500
.Left = 100
.Height = 4300
.Width = 5500
.Visible = True
.StatusBar = True
.MenuBar = True
If Option1.Value = True Then
'MsgBox "wow"
.Navigate2 App.Path & "/" & "singers/" & v2
Else
.Navigate2 App.Path & "/" & v2
End If
End With
' cbQuit
If nnTABS > 1 Then
Load cbQuit(nnTABS - 1)
Load cbRefesh(nnTABS - 1)
End If
With cbQuit(nnTABS - 1)
.Container = SSTab1
.Top = 500
.Left = 500
.Height = 300
.Width = 900
.Visible = True
End With
End With
End Sub
Tony
One last try regarding my demo, 3 questions ..
Q1.
When you say you get the error, which location?
Q2.Code:Private Sub cbAddTab_Click()
With List1
.Top = 4500
.Left = 4000
.Height = 1000
.Width = 1300
.Visible = True ' << location 1
.AddItem "cme.com", 0
.AddItem "yahoo.com", 1
.AddItem "google.com", 2
.AddItem "vbforums.com", 3
End With
With SSTab1
If nnTABs = 0 Then
.Visible = True ' << location 2
.Top = 4500
Also, check this ...
VB6 IDE > Project > References
Do you have a "check" in the following References? (see image below)
Q3.
I have SP5
What SP do you have for VB6?
Spoo
.
Q1 Answer : I have error in location 2
Q2 Answer :I have all those refrences checked but i got Microsoft word 9 object library instead of 11 and also i got Microsoft DAO 3.51 object library checked too
Q3 Answer: i coundn't find out what SP is installed but all i know it is Microsoft virsual basick 6 for 32 bit window development version 8176
Tony
OK for1 and 2.
For 3, you can find the SP by ... Help > About Microsoft Visual Basic
The first line will read Microsoft Visual Basic 6.0.
The SP (if you have any) immediataely follows.
For instance, mine reads as Microsoft Visual Basic 6.0 (SP5).
Spoo