'æ·»å ä¸ä¸ªè®¡æ¶å¨ Timer1 ï¼ä¸ä¸ªå¾åæ¡ Image1
Option Explicit
Dim dx 'å®ä¹ä¸¤ä¸ªçªä½å±åé
Dim dy 'åå«åæ¾Xï¼Y æ¹åååå¢é
Private Sub Form_Load() 'åå§å
Timer1.Enabled = True
Timer1.Interval = 100
dx = Form1.Width / (Rnd * 150 + 200)
dy = Form1.Height / (Rnd * 150 + 200)
End Sub
Private Sub Timer1_Timer()
Image1.Top = Image1.Top + dy 'éè¿æ¹å top å±æ§æ¹åé«åº¦
Image1.Left = Image1.Left + dx
If Image1.Top <= 0 Then dy = -dy 'å¦â碰å£âååå
If Image1.Left <= 0 Then dx = -dx
If Image1.Top >= Form1.Height - Image1.Height Then dy = -dy
If Image1.Left >= Form1.Width - Image1.Width Then dx = -dx
End Sub
温馨提示:答案为网友推荐,仅供参考