0

I'm trying to add a tabPage to an existing TabControl named TabControl4 I went all over it with the Debugger and everything is fine, but it won't show the TabPage in the TabControl. That's the code, Notice all the information being added to the TabPage is retrieved from a database so don't pay any attention to it, plus the software is in Hebrew so just ignore the Hebrew Strings.

Table = DataBase.OpenRecordset("AthInj")
    Table.Index = "PrimaryKey"
    Table.Seek("=", AthId)
    Dim day1() As String = Table.Fields("injDay1").Value.ToString.Split("^")
    Dim month1() As String = Table.Fields("injMonth1").Value.ToString.Split("^")
    Dim year1() As String = Table.Fields("injYear1").Value.ToString.Split("^")
    Dim day2() As String = Table.Fields("injDay2").Value.ToString.Split("^")
    Dim month2() As String = Table.Fields("injMonth2").Value.ToString.Split("^")
    Dim year2() As String = Table.Fields("injYear2").Value.ToString.Split("^")
    Dim injs() As String = Table.Fields("inj").Value.ToString.Split("$")
    Dim treats() As String = Table.Fields("treat").Value.ToString.Split("$")
    Dim rehabs() As String = Table.Fields("rehab").Value.ToString.Split("$")
    For i As Integer = 0 To injs.Length - 2
        Dim tp As New TabPage
        tp.Text = "פציעה " & (i + 1)
        tp.Name = "inj" & i
        Dim bday1 As New ComboBox
        Dim bmonth1 As New ComboBox
        Dim byear1 As New ComboBox
        Dim bday2 As New ComboBox
        Dim bmonth2 As New ComboBox
        Dim byear2 As New ComboBox
        Dim da As Label
        Dim label1 As Label
        Dim label3 As Label
        Dim label4 As Label
        Dim multiText As New TextBox
        Dim ill As New TextBox
        Dim date2 As Label
        Dim rehabText As New TextBox
        da = setLabel("מתאריך:", "injda" & i, 17, 560)
        label1 = setLabel("הפציעה/מחלה:", "inj" & i, 133, 490)
        date2 = setLabel("עד לתאריך:", "date2" & i, 67, 560)
        label3 = setLabel("דרכי הטיפול:", "injtreat" & i, 187, 473)
        label4 = setLabel("דרכי השיקום:", "injrehab" & i, 326, 470)
        copyCombo(bday2, bday, i, 60, bday.Width, 71)
        copyCombo(bmonth2, bmonth, i, 230, bmonth.Width, 71)
        copyCombo(byear2, byear, i, 396, byear.Width, 71)
        bday2.Name = "bday2" & i
        bmonth2.Name = "bmonth2" & i
        byear2.Name = "byear2" & i
        byear2.SelectedIndex = byear2.FindStringExact(year2(i))
        bmonth2.SelectedIndex = month2(i)
        bday2.SelectedIndex = day2(i)
        copyCombo(bday1, bday, i, 60, bday.Width, da.Top + 4)
        copyCombo(bmonth1, bmonth, i, 230, bmonth.Width, da.Top + 4)
        copyCombo(byear1, byear, i, 396, byear.Width, da.Top + 4)
        byear1.SelectedIndex = byear1.FindStringExact(year1(i))
        bmonth1.SelectedIndex = month1(i)
        bday1.SelectedIndex = day1(i)
        setTextBox(ill, 138, 80, "ill" & i, False, ScrollBars.None, 400)
        ill.Text = injs(i)
        setTextBox(multiText, 191, 32, "treatText" & i, True, ScrollBars.Vertical, 399)
        setTextBox(rehabText, 330, 32, "rehabText" & i, True, ScrollBars.Vertical, 399)
        multilineToBox(treats(i), multiText)
        multilineToBox(rehabs(i), rehabText)
        With tp.Controls
            .Add(rehabText)
            .Add(ill)
            .Add(date2)
            .Add(bday2)
            .Add(bmonth2)
            .Add(byear2)
            .Add(da)
            .Add(label1)
            .Add(label3)
            .Add(label4)
            .Add(bday1)
            .Add(bmonth1)
            .Add(byear1)
            .Add(multiText)
        End With
        tp.AutoScroll = True
        tp.BackColor = Color.White
        tp.RightToLeft = Windows.Forms.RightToLeft.Yes
        TabControl4.Controls.Add(tp)
    Next
4

1 回答 1

0

我刚刚用空白表单敲了一个小测试应用程序,然后添加了一个 TabControl 并将其命名为 tabcontrol1。

然后在表单加载事件中添加以下内容

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load

    Dim textbox1 As New TextBox With {.Text = "Textbox 1"}
    Dim tabPage1 As New TabPage With {.Text = "TabPage 1"}

    Dim textbox2 As New TextBox With {.Text = "Textbox 2"}
    Dim tabPage2 As New TabPage With {.Text = "TabPage 2"}


    tabPage1.Controls.Add(textbox1)
    tabPage2.Controls.Add(textbox2)

    TabControl1.TabPages.Add(tabPage1)
    TabControl1.TabPages.Add(tabPage2)

End Sub

一切正常。我认为你的代码中唯一有问题的是你有 TabControl4.Controls.Add(tp) 而不是 TabControl4。标签页 .Add (tp)

于 2011-08-31T12:21:42.493 回答