Dim Ix As Variant, Iy As Variant
Private Sub Form_Activate()
Timer1.Enabled = False
End Sub
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 Variant, n As Variant
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 And n = Iy Then
Timer1.Enabled = False
End If
Image1.Move m, n
End Sub
这次我试过了,成功了。