Dim z As Boolean
Dim X As Boolean
Private Sub Form_Load()
Timer1.Interval = 10: Timer1.Enabled = True
With Shape1
.Shape = 3: .FillColor = vbRed
.FillStyle = 0: .BackColor = vbRed
.Width = 400
End With
End Sub
Private Sub Timer1_Timer()
If Not z Then Shape1.Left = Shape1.Left - 60 Else Shape1.Left = Shape1.Left + 60
If Not X Then Shape1.Top = Shape1.Top + 60 Else Shape1.Top = Shape1.Top - 60
If Shape1.Left < 0 Then Beep: z = True
If Shape1.Left + Shape1.Width > ScaleWidth Then Beep: z = False
If Shape1.Top < 0 Then Beep: X = False
If Shape1.Top + Shape1.Height > ScaleHeight Then Beep: X = True
End Sub
这样是不是更简单点啊!