Option Explicit Dim xx As Long Dim yy As Long Dim tx As Long Dim ty As Long Private Sub Command1_Click() Timer1.Enabled = True Timer1.Interval = 50 Me.Line (0, 0)-(4500, 3000), vbRed, B Me.DrawMode = 10 xx = 0 '起始坐标 yy = 0 tx = 60 '移动偏差 ty = 45 Me.Circle (xx, yy), 30, vbBlue '先画一个小球 End SubPrivate Sub Timer1_Timer() Me.Circle (xx, yy), 30, vbBlue xx = xx + tx yy = yy + ty If xx >= (4500 - 15) Or xx <= (0 - 15) Then '减去15是小球的半径,如果需要控制的更加严格,可以修改15为别的数值,例如60 tx = -tx End If If yy >= (3000 - 15) Or yy <= (0 - 15) Then ty = -ty End If Me.Circle (xx, yy), 30, vbBlue End Sub
Option Explicit Dim xx As Long Dim yy As Long Dim tx As Long Dim ty As Long Private Sub Command1_Click() Timer1.Enabled = True Timer1.Interval = 50 Me.Line (0, 0)-(4500, 3000), vbRed, B Me.DrawMode = 10 xx = 0 '起始坐标 yy = 0 tx = 60 '移动偏差 ty = 45 Me.Circle (xx, yy), 30, vbBlue '先画一个小球 End SubPrivate Sub Timer1_Timer() Me.Circle (xx, yy), 30, vbBlue xx = xx + tx yy = yy + ty If xx > (4500 - 60) Or xx < 60 Then '这里的第二个条件应该是正的,不是负数 '减去15是小球的半径,如果需要控制的更加严格,可以修改15为别的数值,例如60 tx = -tx End If If yy > (3000 - 45) Or yy < 45 Then ty = -ty End If Me.Circle (xx, yy), 30, vbBlue End Sub
Dim xx As Long
Dim yy As Long
Dim tx As Long
Dim ty As Long
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 50
Me.Line (0, 0)-(4500, 3000), vbRed, B
Me.DrawMode = 10
xx = 0 '起始坐标
yy = 0
tx = 60 '移动偏差
ty = 45
Me.Circle (xx, yy), 30, vbBlue '先画一个小球
End SubPrivate Sub Timer1_Timer()
Me.Circle (xx, yy), 30, vbBlue
xx = xx + tx
yy = yy + ty
If xx >= (4500 - 15) Or xx <= (0 - 15) Then '减去15是小球的半径,如果需要控制的更加严格,可以修改15为别的数值,例如60
tx = -tx
End If
If yy >= (3000 - 15) Or yy <= (0 - 15) Then
ty = -ty
End If
Me.Circle (xx, yy), 30, vbBlue
End Sub
Dim xx As Long
Dim yy As Long
Dim tx As Long
Dim ty As Long
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 50
Me.Line (0, 0)-(4500, 3000), vbRed, B
Me.DrawMode = 10
xx = 0 '起始坐标
yy = 0
tx = 60 '移动偏差
ty = 45
Me.Circle (xx, yy), 30, vbBlue '先画一个小球
End SubPrivate Sub Timer1_Timer()
Me.Circle (xx, yy), 30, vbBlue
xx = xx + tx
yy = yy + ty
If xx > (4500 - 60) Or xx < 60 Then '这里的第二个条件应该是正的,不是负数
'减去15是小球的半径,如果需要控制的更加严格,可以修改15为别的数值,例如60
tx = -tx
End If
If yy > (3000 - 45) Or yy < 45 Then
ty = -ty
End If
Me.Circle (xx, yy), 30, vbBlue
End Sub