SSTab array to add as many tabs as you want?
Hello!
I want to create an SSTab array to add as many tabs as I want. I ave created an SStab and I have added a PictureBox. I want a button whose function is add as many tabs with a picture box in the middle of each table (all the tables are equal).
For example, with a limit of 30 tabs would be fine.
Anybody knows how to program it?
1 Attachment(s)
Re: SSTab array to add as many tabs as you want?
I haven't done it with a picturebox, but I've done it with labels, comboboxes, and commandbuttons. A picturebox would be the same. I'll show you some sample code to do it just for a label.
Now, to start with, I just placed an invisible zeroth indexed label on the form. You could create the label from scratch, but having a zeroth label was just easiest.
Also, you have to do this in Form_Activate, not Form_Load. Therefore, you need a module-level-flag to specify whether or not you've already done it, so you don't do it twice (or more).
With a reference to TabCtl32.ocx, here's the code. A project is also attached:
Code:
Option Explicit
'
Dim bAlreadyActive As Boolean
Dim ctlIdxAdd As Long
'
Private Sub Form_Activate()
Dim i As Long
Dim iCnt As Long
Dim iTab As Long
Dim iTabRows As Long
'
If bAlreadyActive Then Exit Sub
bAlreadyActive = True
'
Dim sArray(1 To 8) As String
sArray(1) = "asdfa"
sArray(2) = "sdfgs"
sArray(3) = "cvbn"
sArray(4) = "rtyu"
sArray(5) = "ghjk"
sArray(6) = "sfdfgdfa"
sArray(7) = "mnvbvb"
sArray(8) = "uyuyu"
'
' Now we build the SSTab.
'
' Just add all the tabs first.
For iTab = LBound(sArray) To UBound(sArray)
' One tab already exists.
If iTab <> LBound(sArray) Then SSTabCtl.Tabs = SSTabCtl.Tabs + 1
Next iTab
'
' Figure out how many tab rows.
'
' And now add all the labels.
iTab = 0
'
For i = LBound(sArray) To UBound(sArray)
iTab = i - LBound(sArray)
SSTabCtl.Tab = iTab
SSTabCtl.TabCaption(iTab) = sArray(i)
'
ctlIdxAdd = ctlIdxAdd + 1
Load Label1(ctlIdxAdd)
Set Label1(ctlIdxAdd).Container = SSTabCtl
'
Label1(ctlIdxAdd).Left = 600
Label1(ctlIdxAdd).Top = 1200 ' This may also need to be adjusted for the number of rows, see following comments.
' iTabRows = (SSTabCtl.Tabs + SSTabCtl.TabsPerRow - 1) \ SSTabCtl.TabsPerRow
' iTabCaptionHeight = SSTabCtl.TabHeight
'
Label1(ctlIdxAdd).Visible = True
Label1(ctlIdxAdd).Caption = sArray(i)
'
Next i
'
' Final setup.
SSTabCtl.Tab = 0
SSTabCtl.SetFocus
End Sub
Enjoy,
Elroy
Re: SSTab array to add as many tabs as you want?
Elroy
I'm familiar with uyuyuy, but what language are the others?
Spoo
Re: SSTab array to add as many tabs as you want?
Re: SSTab array to add as many tabs as you want?
It's gotta be that crazy language those weirdos who start their arrays at 1 instead of 0 speak. :eek2:
Re: SSTab array to add as many tabs as you want?
hahaha, yeah, truth be told, I flip back and forth between using ZERO and ONE as the array base. In fact, I often have to check my own code to figure out which way I did it.
Somewhat in my own defense, even Microsoft is incredibly inconsistent about this. For instance, collection items start indexing at ONE, whereas a simple ListBox starts indexing at ZERO. There are a plethora of examples like this.
That's also one reason that I try to lean heavily on LBound and UBound when writing generic functions that deal with arrays. :)
There are also circumstances (which I think are reasonable) where I might Dim an array as Dim a(-10 to 30) As whatever.
Y'all Take Care,
Elroy
1 Attachment(s)
Re: SSTab array to add as many tabs as you want?
Thank you for your help Elroy but I am trying to do something different.
I have this Tab and this Button:
Attachment 152313
With this code, when I Click the button, more tabs are added but I want to add also the picturebox of the first tab in the same position.
Code:
Private Sub Add_New_Tab_Click()
MyTab.Tabs = MyTab.Tabs + 1
End Sub
Re: SSTab array to add as many tabs as you want?
ams16,
The code I gave you provides all the clues on how to do that. Once you create a new tab, use the .Tab property to make that new tab the active tab. Then, assuming your picturebox is indexed, use the Load statement to create more copies of it. Once you've got a copy of it, use its .Container property to set your SSTab as the new picturebox's container. Then, the only thing left is to play around with the new picturebox's .Top and .Left property to position it where you want on the tab.
Basically, I showed you how to do it with a label in the above code. With respect to what you're trying to do, a label and a picturebox would be treated exactly the same.
Please study my code above. It truly does have the answers in it. Also, try running the attached project and watch what it does. You could just replace my label with a picturebox and basically get exactly what you're asking for.
Good Luck,
Elroy
EDIT1: And just as an FYI, you must set the SSTab's active tab (with the .Tab property) before you set your picturebox's .Container property. The way SSTab works, it's always going to be the active tab. Just as further FYI, the SSTab appears to be a series of containers, but it's not. It's just a single container, regardless of how many tabs it has. It just (internally) moves the contained controls around (out of view) to create the effect/illusion of multiple containers. That's why it's important that the tab you wish to use be set as the active tab before using SSTab as a container for a new control.
3 Attachment(s)
Re: SSTab array to add as many tabs as you want?
Here, I did it for you just like you wanted:
Code:
Option Explicit
Private Sub Command1_Click()
Dim iPicLeft As Long
Dim iPicTop As Long
'
' We must save the top and left while the 0 tab is active.
SSTabCtl.Tab = 0
iPicLeft = Picture1(0).Left
iPicTop = Picture1(0).Top
'
' Now create the new tab and picturebox.
SSTabCtl.Tabs = SSTabCtl.Tabs + 1
SSTabCtl.Tab = SSTabCtl.Tabs - 1
Load Picture1(SSTabCtl.Tabs - 1)
Set Picture1(SSTabCtl.Tabs - 1).Container = SSTabCtl
' Now show on the current tab.
Picture1(SSTabCtl.Tabs - 1).Left = iPicLeft
Picture1(SSTabCtl.Tabs - 1).Top = iPicTop
Picture1(SSTabCtl.Tabs - 1).Visible = True ' New controls are always hidden.
End Sub
Attachment 152323
Attachment 152325
Project is attached.
Probably, the problem you were having is that your "master" picturebox wasn't just sitting on the form. It was already on the tab. When you change the active tab, you can no longer trust the .Left property of the picturebox on the first tab. And again, that's because the SSTab control isn't a series of containers. It's a single container that moves the controls around to create the illusion of multiple containers.
Re: SSTab array to add as many tabs as you want?
Quote:
Originally Posted by
Elroy
The code I gave you provides all the clues on how to do that .... Once you've got a copy of it, use its .Container property to set your SSTab as the new picturebox's container.
Indeed it did.
I'd offer that reference to the .Container property is key (at least that was the bit I'd have missed).
Spoo
2 Attachment(s)
Re: SSTab array to add as many tabs as you want?
ams
In addition to Elroy's definitive snippet in his post #9, let me offer the following:
- Assumed
- You placed the SSTab control on your form
- You then placed a PB control on the SSTab control, and manually set the Index property to 0
- May be of interest
- You change some of PB properties by code .. say, in your Form_Load() sub
- These changes will be "remembered" each time you click "Add New Tab"
Here is a demo "before" image
Attachment 152333
.. in which the following was used to change some of the PB's properties
Code:
With PBsst(0)
.Width = 4000
.Height = 1800
.BackColor = vbBlue
End With
When Tab1 is added, those properties are "remembered"
Attachment 152335
HTH
Spoo