我创建了一个程序,根据从组合框中选择的数字动态创建文本框。问题是当我将数字从大数字改为小数字时,文本框保持相同的ex(10然后是3)。 see this image 我尝试输入一个代码来删除* for循环之前的文本框但是它不起作用。
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
num = ComboBox1.Text
Dim tp As TabPage = tabControl1.TabPages(0)
*For i = 1 To num
Dim TB As New TextBox
TB.Size = New System.Drawing.Size(60, 20)
TB.Font = New System.Drawing.Font("arial", 20)
TB.Location = New Point(10, i * 40)
TB.Name = "tbt" & i
Select Case i
Case 1 To 5
TB.Location = New Point(10, i * 45)
Case 6 To 10
Dim i2 As Integer = i - 5
TB.Location = New Point(80, i2 * 45)
End Select
tp.Controls.Add(TB)
Next
End Sub
注意:我在没有tabcontrol的情况下尝试了这种方法,它运行得很好。
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
_Textboxes.ForEach(New Action(Of TextBox)(AddressOf Controls.Remove))
_Textboxes.Clear()
num = ComboBox1.Text
...
End Select
Controls.Add(TB)
_Textboxes.Add(TB)
Next