Results 1 to 2 of 2

Thread: Dynamic tab control - adding tabs

  1. #1
    rbharris is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2006
    Posts
    14
    Reputation
    87

    Dynamic tab control - adding tabs

    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 AsNew 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
    EndWith

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

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

    Thanks for any advice.

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,177
    Reputation
    2368
    Instead of Me.Controls use theTabPage.Controls.
    Code:
    Dim tp As New TabPage("some tab text")
    TabControl1.TabPages.Add(tp)
    Dim pb As New PictureBox
    tp.Controls.Add(pb)
    

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking