我想以表格格式动态创建TextBoxes。到目前为止,我成功地以垂直格式创建了10个文本框。但我想创建10X10网格的文本框。这是代码。此代码成功运行,但只创建10个文本框。我知道代码中存在一个小错误,但我没有得到它。请帮忙
Dim XPos, YPos As Integer
Dim i As Integer = 1
Dim j As Integer = 1
Dim newBox As TextBox
XPos = 20
YPos = 30
For i = 1 To 10
For j = 1 To 10
newBox = New TextBox
newBox.Name = "txtR" & i & "C" & j
newBox.Size = New Drawing.Size(54, 22)
newBox.Location = New Point(XPos, YPos)
newBox.Text = newBox.Name
Me.Controls.Add(newBox)
Next
YPos += 30
Next
答案 0 :(得分:1)
以下代码可以帮助您
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim XPos, YPos As Integer
Dim i As Integer = 1
Dim j As Integer = 1
Dim newBox As TextBox
XPos = 20
YPos = 30
For i = 1 To 10
XPos = 20
For j = 1 To 10
newBox = New TextBox
newBox.Name = "txtR" & i & "C" & j
newBox.Size = New Drawing.Size(54, 22)
newBox.Location = New Point(XPos, YPos)
newBox.Text = newBox.Name
Me.Controls.Add(newBox)
XPos += newBox.Width + 5
Next
YPos += 30
Next
End Sub