Private Sub Timer1_Timer()
 If Picture1.Top > 0 Then
    Picture1.Top = Picture1.Top - 1000
    Picture1.Left = Picture1.Left + 1000
Else
        Picture1.Top = Picture1.Top + 1000
        Picture1.Left = Picture1.Left - 1000
End Sub
为什么在Top=0时没有反应?

解决方案 »

  1.   

    当然没反应If Picture1.Top >= 0 Then
    这样才有
      

  2.   

    是不是这样Dim FX_X As Boolean
    Dim FX_Y As Boolean
    Private Sub Form_Load()
      Timer1.Interval = 10
    End SubPrivate Sub Timer1_Timer()
    If FX_Y = True Then
       Picture1.Top = Picture1.Top - 20: If Picture1.Top <= 0 Then FX_Y = False
    Else
       Picture1.Top = Picture1.Top + 20: If Picture1.Top >= Form1.Height - Picture1.Height Then FX_Y = True
    End If
    If FX_X = True Then
       Picture1.Left = Picture1.Left - 20: If Picture1.Left <= 0 Then FX_X = False
    Else
       Picture1.Left = Picture1.Left + 20: If Picture1.Left >= Form1.Width - Picture1.Width Then FX_X = True
    End If
    End Sub
      

  3.   

    '放6个控件Picture1数组0到5
    Dim FX1_X(5) As Boolean
    Dim FX1_Y(5) As Boolean
    Private Sub Form_Load()
      Timer1.Interval = 10
    End SubPrivate Sub Timer1_Timer()
    For i = 0 To 5
      Call ObjMove(Picture1(i), FX1_X(i), FX1_Y(i))
    Next
    End SubSub ObjMove(Obj As Object, FX_X, FX_Y)
    If FX_Y = True Then
       Obj.Top = Obj.Top - 20: If Obj.Top <= 0 Then FX_Y = False
    Else
       Obj.Top = Obj.Top + 20: If Obj.Top >= Form1.Height - Obj.Height - 300 Then FX_Y = True
    End If
    If FX_X = True Then
       Obj.Left = Obj.Left - 20: If Obj.Left <= 0 Then FX_X = False
    Else
       Obj.Left = Obj.Left + 20: If Obj.Left >= Form1.Width - Obj.Width Then FX_X = True
    End IfEnd Sub
      

  4.   

    Dim x, y
    Private Sub Form_Load()
      Timer1.Interval = 10
      x = 20
      y = 20
    End SubPrivate Sub Timer1_Timer()
      Shape1.Move Shape1.Left + x, Shape1.Top + y
      If Shape1.Left < 1 Then x = Abs(x)
      If Shape1.Top < 1 Then y = Abs(y)
      If Shape1.Left > Form1.Width - Shape1.Width Then x = -Abs(x)
      If Shape1.Top > Form1.Height - Shape1.Height - 300 Then y = -Abs(y)
    End Sub