I have a TabControl into which, at runtime, add a tabpage and a control to the tabpage created. I know how to create a tabpage. But I cant figure out a way how to create both at runtime.
Thanks in advance,
I find the easiest way to figure this out is to place the controls in the IDE then look at the <form>.Designer.vb file that is created when you save. If you do that the sequence becomes (with a little rearranging for personal taste)
Create the tab control and add it to the form
Create the tab pages and add them to the tab control
Create controls for the individual tab pages and add them to that page
Here is some sample code to use on a blank form
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Create the tab control and add it to the main form
Dim tbc As New System.Windows.Forms.TabControl()
tbc.Location = New Point(10, 50)
tbc.Name = "tbcMyTab"
'Create three tab pages and add them to the tab control
For i As Integer = 0 To 2
Dim tbp As New System.Windows.Forms.TabPage()
tbp.Text = "Page " & i
'Create a text control and add it to the last tab page
Dim txt As New TextBox
txt.Text = "default text"
Keep in mind that unless you declare tbc at the class level you will have to refer to the control in other subs/functions as
Dim tbc As TabControl = Me.Controls("tbcMyTab")
tbc.TabPages ... etc
The same thing applies to any other controls you add to the tab pages.