Dynamic tab control - adding tabs

rbharris

Member
Joined
May 26, 2006
Messages
14
Programming Experience
Beginner
I have a bassic understanding for dynmically adding controls to a form however I am having a hard time adding tabs to a tab control. Adding "a tab" with a name on it is simple enough but I can't seem to fiugre out how to add dynamic content to the tab once it's created.

Basically, I have a text file that has a list of names.
When my form loads, it reads that file and creates Tabs based on the names.
I then want to add, for example, a picture box and some labels and a text box, to the tabs.
The text file changes over time so should my tab control.

I don't even have any code to put here because I'm completely puzzled. The only thing I have is when my app is reading the text file I have a statement like this:

Tab.TabPages.Add(petName)

where petName is a string variable for the names of pets in the text file.

For my controls to add to the tab I have something like this:

Dim petPicture As New PictureBox
With petPicture
.Name =
"picBox" & petName
.Size =
New System.Drawing.Size(150, 150)
.Location =
New System.Drawing.Point(14, 40)
.BackColor = Color.Black
.Enabled =
True
.Visible = True
End With

Me.Controls.AddRange(New Control() {petPicture})

How do I get the above on my dynamically created Tab?

Thanks for any advice.
 
Instead of Me.Controls use theTabPage.Controls.
VB.NET:
Expand Collapse Copy
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] tp [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] TabPage([/SIZE][SIZE=2][COLOR=#800000]"some tab text"[/COLOR][/SIZE][SIZE=2])
TabControl1.TabPages.Add(tp)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] pb [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] PictureBox
tp.Controls.Add(pb)
[/SIZE]
 
Back
Top