by Narayanan Thiagarajan (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 10th April 2006
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
Adding Controls to Tabs (Very Easy 5 Lines Code only)
API Declarations
'1. Add and setup the tabstrip control with the number of tabs desired.
'2. Add 1 frame control for each tab. Make them each the same height and width.
'Name each with something like fraFirstTab, fraSecondTab, etc.
'3. Add the controls that you want to appear when the first tab is clicked to
'fraFirstTab. Repeat this for each remaining tab (use fraSecondTab for the second tab, etc.)
'4. set the Top and Left properties for all frames to the same value so that it
'appears within the tabstrip control. You may need to adjust the tabstrip height
'and width to accomidate this.
'5. Set the Visible property for all frame to True.
'6. Select fraFirstTabe and insure that it is on top of the ZOrder. Do this
'by Selecting Format -> Order and see what options are available. If "Bring to
'Front" is grayed out and "Send to Back to in black, then its ok, If not, click
'"Bring to Front".
'7. Add the following code to the Click event procedure of your tabstrip control:
'Select Case TabStrip1.SelectedItem.Index
'Case 1: fraFirstTab.ZOrder 0
'Case 2: fraSecondTab.ZOrder 0
'add 1 CASE statement for each tab. Change the frame
'control name to correspond to the tab that has been selected.
'End Select
'8. What SHOULD happen is the the frame that corresponds to the tab selected is
'moved to the top of the ZOrder, overlaying the other frames.
'-----------------------------------
'I had an application in which I used a tabstrip. I used a frame for each tab in the
'Tabs collection and added the controls to the frame for the corresponding tab.
'Then in code, when the user clicked a particular tab, I would set the Visible property
'of all the frames to false and then set the Visible for the fram that corresponds to
'the tab selected to true, making it visible.
'---------------------------------
'Bear in mind that there is a limit to the number of controls that you can have on a form.
'Depending on the number of tabs you want and the number of controls that will be added to
'your interface, you may reach that limit (256 I believe.). If you will be having more than
'that many controls, you may want to explore creating your own user controls, where the contents
'of each tab is its own custom control. This gets you around the control count limit, but you
'need to be comfortable with handling events generating by the custom controls (WithEvents, etc.)
Private Sub TabStrip1_Click()
Select Case TabStrip1.SelectedItem.Index
Case 1: Frame1.ZOrder 0
Case 2: Frame2.ZOrder 0
Case 3: Frame3.ZOrder 0
Case 4: Frame4.ZOrder 0
End Select
End Sub