Click here to Skip to main content
15,883,531 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Set the BackColor to SSTab in VB6 (workaround)

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
31 Aug 2010CPOL 17.9K   1  
I couldn't really find any solution to this, but after this workaround did what I needed I figured I could share it. The actual tabs will not change color with this workaround, but I can live with that.

I only tested this with SSTab having orientation = top .

Private Sub SetSSTabBackColor(SSTbCntrl As SSTab, lColor As Long)
Dim ctl As Control
Dim CtlTop As Long, CtlLeft As Long, CtlWidth As Long, CtlHeight As Long
Dim i As Integer, CtlFound As Boolean
Dim SSTabMargin As Integer
    
    SSTbCntrl.Visible = False
    SSTabMargin = 40
    CtlTop = SSTbCntrl.TabHeight + SSTabMargin
    CtlLeft = SSTabMargin
    CtlWidth = SSTbCntrl.Width - (SSTabMargin * 2) + 10
    CtlHeight = SSTbCntrl.Height - SSTbCntrl.TabHeight - (SSTabMargin * 2) + 10
    
    ' Loop through tabs
    For i = 0 To SSTbCntrl.Tabs - 1
        CtlFound = False
        For Each ctl In Controls
            If ctl.Name = "SSBCCntrl" & i Then
                CtlFound = True
            End If

        Next ctl
        If CtlFound Then
                'control exists - don't create, just modify
                Controls("SSBCCntrl" & i).Move CtlLeft, CtlTop, CtlWidth, CtlHeight
                Controls("SSBCCntrl" & i).Caption = ""
                Controls("SSBCCntrl" & i).BackColor = lColor
            Else
                'control does not exist - create
                Set ctl = Controls.Add("vb.label", "SSBCCntrl" & i, Me)
                SSTbCntrl.Tab = i
                Set ctl.Container = SSTbCntrl
                ctl.Visible = True
                ctl.Move CtlLeft, CtlTop, CtlWidth, CtlHeight
                ctl.Caption = ""
                ctl.BackColor = lColor
        End If
        
    Next i
    SSTbCntrl.Tab = 0
    SSTbCntrl.Visible = True
End Sub


You can access the subroutine from the activate or resize event (not load)
Private Sub Form_Activate()
    SetSSTabBackColor SSTab1, vbRed
End Sub

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --