我想知道在文本框中打印文本时如何使用arraylist存储不同的字符串并使用字符串。
我很感激anyhelp
我已经这样做了,无论如何打印不同的单词,因为它只在所有文本框上打印“Apple”。另外我如何使用文本框从userinnput在arraylist上存储字符串?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each x As TextBox In mk
x.Text = "Apple"
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
mk.Add(TextBox1)
mk.Add(TextBox2)
mk.Add(TextBox3)
mk.Add(TextBox4)
End Sub
结束班
答案 0 :(得分:0)
如果要在每个文本框中存储不同的字符串,则无法使用循环。例如,你有这个:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each x As TextBox In mk
x.Text = "Apple"
Next
End Sub
但是你需要这样的东西:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Textbox1.Text = "Apple"
Textbox2.Text = "Banana"
Textbox3.Text = "Pear"
Textbox4.Text = "Strawberry"
End Sub
如果要将文本存储在每个文本框中而不是文本框中,可以执行以下操作:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
mk.Add(TextBox1.Text)
mk.Add(TextBox2.Text)
mk.Add(TextBox3.Text)
mk.Add(TextBox4.Text)
End Sub