Use the SetParent API function.
In VB6 there is a limit of 255 separately named controls on one form. You usually don't run afoul of this restriction because 255 is a lot of controls. One case where you might have trouble is if you have a TabStrip with lots of controls on lots of tabs.
One way to get around the restriction is to use control arrays because the controls in an array don't count separately. In particular, you can often put all of your labels in one array.
This example uses another approach. It reparents PictureBoxes containing controls from other forms onto the form containing the TabStrip.
Windows draws the controls inside the new parent but you can still refer to the control on the original form in your Visual Basic code so that's how you interact with the control. The original form also contains the controls' event handlers.
This program makes an array m_PicTab(1 To m_MaxTab) of PictureBoxes to hold references to the controls loaded from the other forms.
When you click on a tab, the program sets Visible = False to hide the PictureBox on the currently selected tab. It then checks m_PicTab to see if the newly selected PictureBox has been loaded yet. If not, the program uses SetParent to move the control into the current form and postions the control.
After the control is loaded, the program makes it visible.
|