Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically create tabs in TabControl

I have a form containing a tabcontrol that I want to modify based on user input on a previous form. I have created a tabcontrol named "TabControl" (creative, I know), and am attempting to add a tab for each value of the array "tabNames()". When I debug the program, I enter the values into the array on the first form, and when the second form loads, I get nothing in my tabcontrol. Any thoughts?

Public Sub frmContent_Load(ByVal sender As Object, ByVal e As EventArgs)
  lblTitle.Text = frmiFormCreator.txtTitle.Text
  For i As Integer = 0 To frmiFormCreator.numberOfTabs
    Dim tabPage(frmiFormCreator.numberOfTabs) As TabPage
    tabPage(i).Text = frmiFormCreator.tabNames(i)
    TabControl.TabPages.Add(tabPage(i))
  Next
End Sub
like image 722
nherrmann Avatar asked Jul 08 '26 22:07

nherrmann


1 Answers

Try creating the TabPage object:

For i As Integer = 0 To frmiFormCreator.numberOfTabs
  Dim newPage As New TabPage()
  newPage.Text = frmiFormCreator.tabNames(i)
  TabControl.TabPages.Add(newPage)
Next

Also, your code looks like it might be creating an extra tab. Maybe you want this:

For i As Integer = 0 To frmiFormCreator.numberOfTabs - 1
like image 183
LarsTech Avatar answered Jul 10 '26 12:07

LarsTech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!