Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1448

Move a control from one tab to another at run-time on the SSTab control

$
0
0
It took me a bit to figure this out, and I see a bit of interest in the SSTab control, so I decided to post this. It's a procedure that allows you to change the tab of a control that's on the SSTab control at run-time.

Code:


Public Sub ChangeTheSSTab(SSctl As Control, ctl() As Control, OldTab As Long, NewTab As Long, Optional bRestoreTheTab As Boolean = False)
    ' Hide the form with the SSTab before doing this.  This will prevent flicker if you're moving several controls.
    ' You must get the OldTab correct or everything blows up. Alternatively, this procedure could have "found" it, but that wastes time.
    ' This procedure does NOT work in form_load, but it DOES work in form_activate.
    ' Also, when using this, don't forget to deal with the TabIndex if you need to !!!!
    Dim OrigTab As Long
    Dim i As Long
    '
    If bRestoreTheTab Then OrigTab = SSctl.Tab
    '
    SSctl.Tab = OldTab
    For i = LBound(ctl) To UBound(ctl)
        If TypeName(ctl(i)) = "Line" Then
            ctl(i).X1 = ctl(i).X1 - 75000
            ctl(i).x2 = ctl(i).x2 - 75000
        Else
            ctl(i).Left = ctl(i).Left - 75000
        End If
    Next i
    SSctl.Tab = NewTab
    For i = LBound(ctl) To UBound(ctl)
        If TypeName(ctl(i)) = "Line" Then
            ctl(i).X1 = ctl(i).X1 + 75000
            ctl(i).x2 = ctl(i).x2 + 75000
        Else
            ctl(i).Left = ctl(i).Left + 75000
        End If
    Next i
    '
    If bRestoreTheTab Then SSctl.Tab = OrigTab
End Sub

It's usage is fairly straightforward, at least to me. :)

Here's an example (in a Form_Activate procedure):

Code:

    Dim ctl() As Control
    '
    ' Change the SSTab of the controls.
    ReDim ctl(1 To 3)
    Set ctl(1) = txtRight1
    Set ctl(2) = txtRight2
    Set ctl(3) = txtRight3
    ChangeTheSSTab tabExamData, ctl(), 4, 2

The SSTab control is named tabExamData. There are three controls moved from tab #4 to tab #2 on the SSTab control. The position on the tab won't change, but the actual tab the controls are on will change. The ctl() is an array of controls so I can move several controls at once. This speeds things up.

Enjoy,
Elroy

Viewing all articles
Browse latest Browse all 1448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>