我正在尝试将tabPage添加到名为TabControl4的现有TabControl中 我用调试器全力以赴,一切都很好,但它不会在TabControl中显示TabPage。 这是代码,注意所有添加到TabPage的信息都是从数据库中检索的,所以不要注意它,加上软件是希伯来文,所以只要忽略希伯来语字符串。
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
答案 0 :(得分: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。 TabPages .Add(tp)