代码很简单,自己看吧(小学的课本俺都忘了,斜率公式居然还GOOGLE了一下)。Option ExplicitPrivate Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Command1_Click() Call MoveCtrl(Command1, 10, 10, 100, 100, 10) End SubPrivate Sub MoveCtrl(dx As Object, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal t As Long) Dim K As Double '斜率 Dim x As Long, y As Long '轧迹上的坐标
Me.ScaleMode = vbPixels If x2 <> x1 Then K = (y2 - y1) / (x2 - x1) For y = y1 To y2 If K = 0 Then '无斜率 x = x1 Else x = (y - y1) / K + x1 End If dx.Move x, y DoEvents Sleep t Next MsgBox "移动完毕!" End Sub
Call MoveCtrl(Command1, 10, 10, 100, 100, 10)
End SubPrivate Sub MoveCtrl(dx As Object, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal t As Long)
Dim K As Double '斜率
Dim x As Long, y As Long '轧迹上的坐标
Me.ScaleMode = vbPixels
If x2 <> x1 Then K = (y2 - y1) / (x2 - x1)
For y = y1 To y2
If K = 0 Then '无斜率
x = x1
Else
x = (y - y1) / K + x1
End If
dx.Move x, y
DoEvents
Sleep t
Next
MsgBox "移动完毕!"
End Sub