斜边每次步进长度定义为step,移动角度假设为r则 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim r As Double = 30 * Math.PI / 180 Dim s As Double = 5 Dim dx As Double = Math.Cos(r) * s Dim dy As Double = Math.Sin(r) * s While TextBox1.Left < Me.Width And TextBox1.Top < Me.Height TextBox1.Left += dx TextBox1.Top += dy Application.DoEvents() Thread.Sleep(20) End While MessageBox.Show("move done") TextBox1.Location = New Point(12, 12) End Sub
static extern bool SetCursorPos(int X,int Y);
timer中设置
dylike问这么简单的问题?还是我没理解对?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim r As Double = 30 * Math.PI / 180
Dim s As Double = 5
Dim dx As Double = Math.Cos(r) * s
Dim dy As Double = Math.Sin(r) * s While TextBox1.Left < Me.Width And TextBox1.Top < Me.Height
TextBox1.Left += dx
TextBox1.Top += dy
Application.DoEvents()
Thread.Sleep(20)
End While
MessageBox.Show("move done")
TextBox1.Location = New Point(12, 12)
End Sub