tags:

views:

1484

answers:

2

Hi,

I am trying to update an old VB6 application. I am struggling with changing the backcolor of the SSTab control at runtime.

I know that I cannot just set the Backcolor to the required colour.

At designtime I have created a label on each tab and then resized the label to the sstab dimensions. Then I set the label backcolor. This works fine.

However, what I really want to do is to do this at runtime so that if a new tab control is added on a form in the future I dont need to manually do this at designtime each time.

I would be grateful if someone can point me in the right direction to create and display a label on every tab of a SSTab control at runtime?

I dont have frames on all the tabs so I dont want to use the frame container to hold the label. I would rather just have the label placed on the tab container at runtime.

Thanks and I look forward to your replies.

+2  A: 

Create one label at design-time, and set it's index to 0. You can later on do Load labelname(newindex) to create more instances of the label. Position them once created, set the background color and you're all done.

svinto
This is what exactly you need to do.
RS Conley
+3  A: 

As svinto says, you can load new controls to a Control Array, but there's a bit more to it than that.

Firstly the new controls are not Visible, so you must set .Visible=True You also need to set the current tab before creating the control to get it sited on that tab.

Assuming you already have the first label on the first tab:

For i = 1 To Me.SSTab1.Tabs - 1
    Me.SSTab1.Tab = i
    Load lblOne(i)
    lblOne(i).Visible = True
Next

Also, this doesn't work in the Form_Load event, but does in Form_Activate

There is another method to create the Labels from scratch rather than using a Control Array, which might be better as you don't need to add the first Label to the form:

Private Sub Form_Activate()
    Dim lbl() As Label
    Dim i As Integer
    Dim name As String

   ReDim lbl(SSTab1.Tabs - 1)
   For i = 0 To Me.SSTab1.Tabs - 1
        Me.SSTab1.Tab = i
        name = "MyLabel" & CStr(i)
        Set lbl(i) = Form1.Controls.Add("VB.Label", name)
        Set lbl(i).Container = Me.SSTab1
        lbl(i).Visible = True
        lbl(i).Caption = name
        lbl(i).Move 40, 345
        lbl(i).BackColor = vbGreen
    Next
End Sub
John Y