Option Explicit
Dim dx As Double
Dim dy As Double
Dim maxtime As Long
Dim aniControl As Control
Private Sub Command1_Click()
BuildAnimation Image1, 24, 56, 576, 56, 2000, 60
End Sub
Private Sub BuildAnimation(myControl As Control, x, y, xx, yy, Optional mtime As Long = 1000, Optional granularity As Long = 100)
Set aniControl = myControl
maxtime = mtime
dx = (xx - x) / (mtime / granularity)
dy = (yy - y) / (mtime / granularity)
aniControl.Move x, y
aniTimer.Interval = granularity
aniTimer.Enabled = True
End Sub
Private Sub aniTimer_Timer()
Static looped As Long
If looped = 0 Then aniControl.Visible = True
If looped < maxtime Then
aniControl.Move aniControl.Left + dx, aniControl.Top + dy
looped = looped + aniTimer.Interval
Else
aniTimer.Enabled = False
aniControl.Visible = False
looped = 0
End If
End Sub
Private Sub Form_Load()
Form1.ScaleMode = vbPixels
End Sub