Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For i As Integer = 0 To 4
Me.Hide()
Form2.Show()
i = i + 1
Next
End Sub
'这是我的有问题的代码 我用于循环,但是form2只出现一次,所以我必须不断按下按钮
答案 0 :(得分:0)
听起来您想要的是要显示表单的4个不同实例。 (毕竟,相同表单不能“出现4次”,因为一旦可见,它就已经可见。)为此,您需要4个实例。像这样:
Private form2Instances As New List(Of Form2)
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For i As Integer = 0 To 4
Dim form2 As New Form2()
form2Instances.Add(form2)
form2.Show()
i = i + 1
Next
Me.Hide()
End Sub
这里的想法是您的班级正在维护Form2
实例的集合,然后单击您的按钮实际上会做一些事情: