当我按一个按钮开始循环时,循环一次,然后冻结

时间:2019-11-09 23:12:21

标签: vb.net

我的程序循环一次后就冻结了。

我尝试替换循环的条件,并使其无限期地循环,但是它总是做同样的事情。

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 
    Button3.Click

        ballX = Button2.Location.X + 1
        ballY = Button2.Location.Y + 1
        Dim g As Integer
        Dim h As Integer

        h = Button2.Location.X


        Do Until h > 856
            Button2.Location = New Point(ballX, ballY)
            Me.Update()
        Loop

    End Sub

应该移动一个按钮,直到碰到程序侧面,然后停止。它所做的只是将按钮移动1px,那么您将无法再与该程序进行交互。有解决办法吗?

1 个答案:

答案 0 :(得分:0)

您尝试过

Do Until h > 856
    Button2.Location = New Point(ballX, ballY)

    ballX = Button2.Location.X + 1
    ballY = Button2.Location.Y + 1
    h = Button2.Location.X

    Me.Update() 
Loop