Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get controll type, controll name from the second panel of SStab 1

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
439
IT
My test code, but dont work!


Code:
Dim ctl As Control
    For Each ctl In Me.Controls
        If ctl.Container Is Me.SSTab Then
            If ctl.Container.Tab = 1 Then
                Debug.Print TypeName(ctl), ctl.Name
            End If
        End If
    Next ctl
 
SSTab may be not a container.
Try this to find the typename, then get others:
Code:
Dim ctl As Control
    For Each ctl In Me.Controls
        Debug.Print TypeName(ctl)
        If TypeOf ctl Is SSTab Then Debug.Print "SSTab"
    Next ctl
End Sub
 
I am presuming that by 'sstab' you actually mean an instance of sstab such as sstab1.

And we'll assume that you are trying to list all the controls on a particular tab on that sstab instance.

Ok, so here's the first bad news - ctl.Container.Tab won't work the way you are hoping (or, knowing you, that someone else hoped). If Container is an sstab, the Tab property merely reflects the currently selected tab, not the tab that the control is on.

Ok, so what property can we use? Well, here's the second bad news. There is no property that allows you to match a control to the tab it is on (that info is hidden deep within the the inner workings of the sstab control away from the nasty prying eyes of VB (the sstab control is a pain).

So, are we stuck~? Not exactly ... but it involves a little inside knowledge. The first bit of knowledge (and one of the reasons the sstab is a pain) is that each tab is NOT an individual container - the control fakes it by simply moving controls that should not display on the current tab away from view. And the bit of knowledge is that the way the sstab control hides controls from view that are not on the current tab is by sliding them a long way to the left (you'd be surprised how often this trick is used by Windows). Quite literally it simply subtracts 75000 from the current' visible left postion to hide it, then add 75000 back when the specific tab the control is on becomes the current tab.

And we can use that info to resolve your problem:

Rich (BB code):
    Dim ctl As Control
    Dim Currenttab As Long
    Dim tabloop As Long
    
    Currenttab = SSTab1.Tab 'capture currently selected tab
    
    For tabloop = 0 To 2 ' for an sstab with 3 tabs
    
        Debug.Print "On tab " & tabloop
        SSTab1.Tab = tabloop
    
        ' Check to see if each control is on an sstab and if so whether it is visible on the currently selected tab
        For Each ctl In Me.Controls
           If ctl.Container Is SSTab1 Then
                If ctl.Left > -500 Then
                    Debug.Print "    "; ctl.Name
                End If
            End If
        Next ctl
     Next
        
    SSTab1.Tab = Currenttab ' revert to originally selected tab
 
"the sstab control is a pain" so true, but there is a way around it.
"Quite literally it [SSTab] simply subtracts 75000 from the current' visible left postion to hide it, then add 75000 back when the specific tab the control is on becomes the current tab" most of the time, if everything works the way it should.

I had the situations where I've placed a few controls on two Tabs, and then when clicking on each Tab I saw controls 'move' South and East (well, down and to the right) every time I've switched the Tabs, until controls left the visible portion of the Tab. Very frustrating.

So, how do you keep track of all the controls on each Tab? Well, you can't. But... you don't have to.
What I did was: instead of placing controls directly on the Tab(s), I just place a Frame on each tab. It is actually a Frame array where the Index of the Frame corresponds to the Tab of the SSTab. If my SSTab has 3 tabs, I have an array of Frames with indexes of 0, 1, and 2. I place Frame(0) on first Tab, Frame(1) on the second tab, etc. And then I place all controls I need on that Frame. What SSTab does is move just one control (a Frame) to some distance -75000 left and it moves it back to where it is supposed to be. But I don't even rely on that, either.

I control this 'placing it back in its place' myself in the code:

Code:
Private Sub SSTab1_Click(PreviousTab As Integer)
 
With fraMyFrame(SSTab1.Tab)
    .Move 150, SSTab1.TabHeight + 150, SSTab1.Width - 300, SSTab1.Height - SSTab1.TabHeight - 300
    .BorderStyle = 0
End With

End Sub

(Yes, I know there are some 'magic' hard-coded numbers here, but that's something I can live with)
 
>I saw controls 'move' South and East (well, down and to the right)

I seem to have a vague recollection that was a bug in one of the common control release versions. I believe it was fixed by the time we got to v6.0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top