On Visual Basic 6.0 you add a TextBox on form and it has a name TextBox1
after that I copy/paste that TextBox on form and I got TextBox1(0)
paste again TextBox1(1)
How to do that on Visual Basic 2012 ??? I copy/paste text box and got Textbox1
Textbox2
? Do you understand the question?
在Visual Basic 6.0上,你在窗体上添加一个TextBox,它有一个名称TextBox1之后,我复制/粘贴表格上的TextBox,我得到TextBox1(0)再次粘贴TextBox1(1)如何在Visual Basic 2012上做到这一点?我复制/粘贴文本框并获得Textbox1 Textbox2?你明白这个问题吗?
I tried to copy paste TextBox1
and I got TextBox2
我试图复制粘贴TextBox1,我得到了TextBox2
The code I want to use is to check the TextBoxes something like
我想要使用的代码是检查TextBoxes之类的东西
Dim i as integer
For i=1 to 5
textbox(i).text="Anel"
Next
2 个解决方案
#1
2
You have to draw FIVE textboxes and ONE button on the form
您必须在表单上绘制五个文本框和一个按钮
(1) Declare a Collection
at class level,
(1)在班级宣布收藏,
(2) In Form_Load
event, add your textboxes to the Collection
(2)在Form_Load事件中,将文本框添加到Collection
(3) You can access all your textboxes with for
loop as shown in following code
(3)您可以使用for循环访问所有文本框,如下面的代码所示
Dim AL As New Collection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AL.Add(TextBox1)
AL.Add(TextBox2)
AL.Add(TextBox3)
AL.Add(TextBox4)
AL.Add(TextBox5)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 1 To AL.Count
AL(i).Text = "Hello"
Next
End Sub
#2
-1
Dim textBoxTemp As TextBox
Dim stringData As String
For index = 0 To 23
stringData = ("txtBoxReal" & index)
textBoxTemp = CType(Me.Controls(stringData), TextBox)
textBoxTemp.Text = 0
Next
#1
2
You have to draw FIVE textboxes and ONE button on the form
您必须在表单上绘制五个文本框和一个按钮
(1) Declare a Collection
at class level,
(1)在班级宣布收藏,
(2) In Form_Load
event, add your textboxes to the Collection
(2)在Form_Load事件中,将文本框添加到Collection
(3) You can access all your textboxes with for
loop as shown in following code
(3)您可以使用for循环访问所有文本框,如下面的代码所示
Dim AL As New Collection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AL.Add(TextBox1)
AL.Add(TextBox2)
AL.Add(TextBox3)
AL.Add(TextBox4)
AL.Add(TextBox5)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 1 To AL.Count
AL(i).Text = "Hello"
Next
End Sub
#2
-1
Dim textBoxTemp As TextBox
Dim stringData As String
For index = 0 To 23
stringData = ("txtBoxReal" & index)
textBoxTemp = CType(Me.Controls(stringData), TextBox)
textBoxTemp.Text = 0
Next