3

我有一个包含选项卡控件的表单,我想根据前一个表单上的用户输入来修改它。我创建了一个名为“TabControl”的选项卡控件(我知道是有创意的),并尝试为数组“tabNames()”的每个值添加一个选项卡。当我调试程序时,我将值输入到第一个表单的数组中,当第二个表单加载时,我的 tabcontrol 中什么也没有。有什么想法吗?

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
4

2 回答 2

6

尝试创建 TabPage 对象:

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

此外,您的代码看起来可能正在创建一个额外的选项卡。也许你想要这个:

For i As Integer = 0 To frmiFormCreator.numberOfTabs - 1
于 2013-03-20T16:00:25.157 回答
1

尝试

Public Sub frmContent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)  
    lblTitle.Text = frmiFormCreator.txtTitle.Text
    For i As Integer = 0 To frmiFormCreator.numberOfTabs
        Dim tabPage As New TabPage(frmiFormCreator.tabNames(i))
        TabControl.TabPages.Add(tabPage)
    Next
End Sub
于 2013-03-20T16:01:33.610 回答