Q: Can I add controls to a tab page dynamically?
Adding controls dynamically is easily done. However, individual tab pages don't each have their own container. Instead, all new objects are added to SftTabs as the container. Any controls added dynamically become part of the tab page that is active at that time. The tab page can be changed using the Current property.
For a simple sample, create a new VB project. On a blank form, add a SftTabs tab control named SftTabs and a button named Command1. Copy the following code:
Dim ButtonCount As Integer
Private Sub Command1_Click()
Dim cmdObject As CommandButton
ButtonCount = ButtonCount + 1
Set cmdObject = Form1.Controls.Add("VB.CommandButton", _ "Button" & ButtonCount)
Set cmdObject.Container = SftTabs1
cmdObject.Left = 500 * Count
cmdObject.Top = 500 * Count
cmdObject.Visible = True
cmdObject.ZOrder 0
End Sub
Each time the button (Command1) is clicked, a blank button control is added to the current tab page. |