HOWTO: Use SetParent to Place Controls on New Tab at Run-TimeID: Q161828
|
In Visual Basic 5.0, you can use the SetParent API to place controls on a
newly-created tab of the SSTab control. You can make these controls
invisible children of the form on which the SSTab control is located at
design-time and make them children of the SSTab control at run-time. Before
removing the tab, you must remove the children controls. You can remove
them by once again making the controls children of the form parent with the
SetParent API.
In Visual Basic 6.0, this technique is not necessary: you can create
controls at run-time.
Control Name Property Value
------------------------------------------------------------------
SSTab SSTab1 (Name) SSTab1
Tabs 3
TabsPerRow 5
Command Button Command1 (Name) Command1
Caption Add Tab
Command Button Command2 (Name) Command2
Caption Remove Tab
Command Button Command3 (Name) Command3
Caption Button on Tab 3
Visible False
ListBox List1 (Name) List1
Visible False
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long,
ByVal hWndNewParent As Long) As Long
Private Sub Command1_Click()
SSTab1.Tabs = 4 'Add a tab to the control
SSTab1.Tab = 3 'Bring this tab to foreground
x& = SetParent(List1.hWnd, SSTab1.hWnd) 'Make tab parent to list1
List1.Visible = True 'Make list1 visible
List1.Move SSTab1.Width \ 10, SSTab1.Height \ 3, SSTab1.Width \ _
3, SSTab1.Height \ 2 'Move list1 to an appropriate location
'Populate ListBox
For i% = 1 To 10
List1.AddItem Str$(i%) & " This is an item in List1"
Next i%
x& = SetParent(Command3.hWnd, SSTab1.hWnd) 'Make tab parent to
'command3
Command3.Visible = True 'Make command3 visible
Command3.Move SSTab1.Width - SSTab1.Width \ 3, SSTab1.Height \ _
3, SSTab1.Width \ 4, SSTab1.Height \ 4 'Move command3 to an
'appropriate position
End Sub
Private Sub Command2_Click()
'You need to remove controls from the tab before removing the tab
List1.Clear 'Clear the ListBox
x& = SetParent(List1.hWnd, Form1.hWnd) 'Make the ListBox a child of
'the form
List1.Visible = False
List1.Move Form1.Width * 0.9, Form1.Height \ 10, Form1.Width \ 10, _
Form1.Height \ 10
x& = SetParent(Command3.hWnd, Form1.hWnd) 'Make command3 a child of
'the form
Command3.Visible = False
Command3.Move Form1.Width * 0.9, Form1.Height * 0.3, Form1.Width \ _
10, Form1.Height \ 10
SSTab1.Tabs = 3 'Remove the tab from the control
SSTab1.Tab = 2 'Bring tab 2 to the foreground
End Sub
Private Sub Command3_Click()
MsgBox "The command button on the tab control is functional"
End Sub
Additional query words: kbVBp500 kbVBp600 kbVBp kbdsd kbDSupport kbControl
Keywords :
Version :
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: June 16, 1999