Results 1 to 11 of 11

Thread: SSTab array to add as many tabs as you want?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2017
    Posts
    39

    Question 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?

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    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
    Attached Files Attached Files
    Last edited by Elroy; Sep 28th, 2017 at 09:03 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: SSTab array to add as many tabs as you want?

    Elroy

    I'm familiar with uyuyuy, but what language are the others?

    Spoo

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: SSTab array to add as many tabs as you want?

    ¯\_(ツ)_/¯
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    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.

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    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
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7

    Thread Starter
    Member
    Join Date
    May 2017
    Posts
    39

    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:
    Name:  tabs.JPG
Views: 667
Size:  30.2 KB

    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

  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    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.
    Last edited by Elroy; Sep 28th, 2017 at 12:46 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  9. #9
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    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
    
    
    Name:  Image1.png
Views: 651
Size:  2.8 KB

    Name:  Image2.png
Views: 688
Size:  3.5 KB

    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.
    Attached Files Attached Files
    Last edited by Elroy; Sep 28th, 2017 at 01:12 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  10. #10
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: SSTab array to add as many tabs as you want?

    Quote Originally Posted by Elroy View Post
    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

  11. #11
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    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:

    1. 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
    2. 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

    Name:  SSTabAdd0.png
Views: 621
Size:  2.6 KB

    .. 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"

    Name:  SSTabAdd1.png
Views: 570
Size:  2.8 KB

    HTH

    Spoo

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width