• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 595
  • Last Modified:

How do I add controls to tabs on the sstab control at run time.

I want to write a program that will start with a single tab on a tabbed dialog control (sstab) and allow additional tabs to be added. Each tab will contain 2 command buttons, a textbox and 4 option buttons. The controls contained in the tab will be from control arrays.

The idea is that, when required, I will add a tab to the tabbed dialog control (easy enough). I will also load a new set of controls (easy enough since they are elements of control arrays).
The problem is that I want the controls to be placed on the tabs. If I use the code:
Set Command1.container = sstab1
Command1 is placed on the first tab.

Is there a way to place the control on a specific tab at run time?
0
chaos_59
Asked:
chaos_59
1 Solution
 
appariCommented:
try this

sstab1.tab = 1
Set Command1.container = sstab1


replace sstab1.tab with the tab no on which you want to show the new control. one more point to note don't do it in form load event. it's not working. write this code in activate event.

Rao

0
 
khamptonCommented:
I haven't worked with SSTAB since VB4.  A little while back, I tried to do exactly what you are doing with VB6.  After spending over an hour trying everything I could think of - I gave up and wrote my own SSTAB control.  Here is how I did it:


I created a UserControl.  I set this control to be a container of other controls.  I used Labels as tabs.  I created methods called AddTab and RemoveTab to dynamically increase/decrease the tabs at runtime.  When a user clicks on a tab (label) I raised an event.

The caller can put as many controls on the usercontrol as desired.  The caller is responsible for hiding/showing controls relative to a specific tab.

Anyway, the bottom line is now I have a tabbed control that I can do anything I want with (I can change colors, accent an open tab, etc).

Try it, its not really that hard...good luck!
0
 
gwgawCommented:
Adding controls to the ssTab in form activate event will work but the
added controls may also be visible on the first tab.

The ssTab control does not have to be visible to add tabs or controls to a
specific tab but it must be initailized or all conrtols will be added to
first tab.

To add controls at startup, place a timer control on your form. Set it's
enabled property to false and the interval to a value that is large enuff
to allow your form to finish loading. Enable the timer on the last line
of form load event.


Private Sub Form_Load()
'Do form load stuff
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Dim i%
Timer1.Enabled = False
SSTab1.TabsPerRow = 4
For i = 2 To 4
    With SSTab1
        'Add a tab
        .Tabs = i
        'Make the added tab the current tab
        .Tab = .Tabs - 1
    End With
    Load Text1(Text1.Count + 1)
    With Text1(Text1.Count)
        'Place text box on the current tab
        .Container = SSTab1
        'Don't forget to set position
        .Left = 120
        .Top = 420
        .Visible = True
        .Text = SSTab1.Tab & " - " & .Index
    End With
Next i
End Sub


This can also be done in a command button's click event or in response to
some other user action. Use a For-Next or Do loop to add as many tabs and
controls as you want.
0
 
chaos_59Author Commented:
Thanks!
I almost had it, but your code showed me where my problems where.
Thanks so much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now