Private Sub AnimationTimer_Timer()
Const R = 500
Static X As Single
Static Y As Single
Static Vx As Single
Static Vy As Single
Static done_before As Boolean
If Not done_before Then
done_before = True
Randomize
Vx = 50 + Rnd * 50
Vy = 50 + Rnd * 50
X = ScaleWidth / 2
Y = ScaleHeight / 2
End If
' Clear the backdrop.
Backdrop.Line (0, 0)-(ScaleWidth, ScaleHeight), _
Backdrop.BackColor, BF
' Draw the circle.
Backdrop.Circle (X, Y), R
Backdrop.Picture = Backdrop.Image
MDIForm1.Picture = Backdrop.Picture
' Move the circle.
X = X + Vx
If (X + R > ScaleWidth) Or (X - R < 0) Then
X = X - Vx
Vx = -Vx
End If
Y = Y + Vy
If (Y + R > ScaleHeight) Or (Y - R < 0) Then
Y = Y - Vy
Vy = -Vy
End If
End Sub
Private Sub MDIForm_Resize()
Backdrop.Move 0, 0, ScaleWidth, ScaleHeight
End Sub
|