Dim 下右 AsBoolean Dim 下左 AsBoolean Dim 上右 AsBoolean Dim 上左 AsBoolean'定义方向 PrivateSub Form_Load() Randomize' 这里让圆随机方向移动 a =Int(Rnd*4) If a =0Then 上左 =False: 上右 =False: 下左 =False: 下右 =True If a =1Then 上左 =False: 上右 =False: 下左 =True: 下右 =False If a =2Then 上左 =False: 上右 =True: 下左 =False: 下右 =False If a =3Then 上左 =True: 上右 =False: 下左 =False: 下右 =False End Sub PrivateSub Timer1_Timer() '移动过程 x = Shape1.Left '提取当前x y = Shape1.Top '提取当前y If 下右 =TrueAnd x + Shape1.Width > Me.Width -140Then 下左 =True: 下右 =False'若方向是 下右 并且碰到 右边 则向 下左 If 下右 =TrueAnd y + Shape1.Width > Me.Height -500Then 上右 =True: 下右 =False'若方向是 下右 并且碰到 下边 则向 上右 If 上右 =TrueAnd x + Shape1.Width > Me.Width -140Then 上右 =False: 上左 =True' 类推.... If 上右 =TrueAnd y <0Then 上右 =False: 下右 =True If 上左 =TrueAnd x <0Then 上左 =False: 上右 =True If 上左 =TrueAnd y <0Then 上左 =False: 下左 =True If 下左 =TrueAnd y + Shape1.Width > Me.Height -500Then 下左 =False: 上左 =True If 下左 =TrueAnd x <0Then 下左 =False: 下右 =True If 上左 =TrueThen x = x -30: y = y -30'判断是什么方向 就怎么移动 If 上右 =TrueThen x = x +30: y = y -30 If 下左 =TrueThen x = x -30: y = y +30 If 下右 =TrueThen x = x +30: y = y +30 Shape1.Move x, y '使用move 函数 移动 End Sub