VB中如何使用MOVE事件来使一张图片移动到鼠标指定位置
我的意思是让那张图片慢慢移动过去不是瞬间完成。。
若用MOVE事件可以先获得鼠标被点击位置
然后让图片判断自己位置慢慢移动到鼠标点击位置。。(用time来控制)
下边是我的想法。。但是实现不了啊。。。
Option Explicit
Dim Ix As Integer, Iy As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Ix = X
Iy = Y
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Timer1_Timer()
Dim m As Long, n As Long, p As Long, q As Long
m = Image1.Left + (Image1.Left - Ix) / Sqr((Image1.Left - Ix) * (Image1.Left - Ix) + (Image1.Top - Iy) * (Image1.Top - Iy))
n = Image1.Top + (Image1.Top - Iy) / Sqr((Image1.Top - Iy) * (Image1.Top - Iy) + (Image1.Left - Ix) * (Image1.Left - Ix))
If m = Ix Or n = Iy Then
Timer1.Enabled = False
End If
Image1.Move m, n
End Sub