“定时器与分支语句的应用”实践指导

 

                  
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 39 Then
       
       
        Timer1.Enabled = True
        Image3.Visible = False
        Image4.Visible = False
        
    End If
    
    If KeyCode = 37 Then
        Timer3.Enabled = True
        Image1.Visible = False
        Image2.Visible = False
        
    End If
    
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = 39 Then
        Timer1.Enabled = False
        
    End If
    
     
    If KeyCode = 37 Then
        Timer3.Enabled = False
    End If
End Sub

Private Sub Form_Load()
   Image1.Top = 4920
   Image1.Left = 0
    Image2.Top = 4920
   Image2.Left = 0
    Image3.Top = 4920
   Image3.Left = 0
    Image4.Top = 4920
   Image4.Left = 0
   
   
   Image1.Visible = True
   Image2.Visible = False
   Image3.Visible = False
   Image4.Visible = False
   
End Sub

Private Sub Timer1_Timer()
Image1.Left = Image1.Left + 100
Image2.Left = Image2.Left + 100
Image3.Left = Image3.Left + 100
Image4.Left = Image4.Left + 100
If Image1.Left > 9600 Then
    Image1.Left = 0
    Image2.Left = 0
End If

If Image1.Visible = False Then
     Image1.Visible = True
     Image2.Visible = False
Else
     Image1.Visible = False
     Image2.Visible = True
End If


If Image1.Left > 7320 And Image1.Left < 8880 Then
   Timer1.Enabled = False
   Timer2.Enabled = True
End If
End Sub

Private Sub Timer2_Timer()
Image1.Visible = False
Image2.Visible = True

Image1.Top = Image1.Top + 50
Image2.Top = Image2.Top + 50
If Image1.Top > 6300 Then
   Image1.Top = 4920
   Image1.Left = 0
    Image2.Top = 4920
   Image2.Left = 0
   Timer1.Enabled = True
   Timer2.Enabled = False
   
End If
End Sub

Private Sub Timer3_Timer()
Image1.Left = Image1.Left - 100
Image2.Left = Image2.Left - 100
Image3.Left = Image3.Left - 100
Image4.Left = Image4.Left - 100
If Image3.Visible = False Then
     Image3.Visible = True
     Image4.Visible = False
Else
     Image3.Visible = False
     Image4.Visible = True
End If
End Sub

Private Sub Timer4_Timer() '
Image1.Left = Image1.Left + 100
Image2.Left = Image2.Left + 100
Image3.Left = Image3.Left + 100
Image4.Left = Image4.Left + 100
Image1.Top = Image1.Top - 50
Image2.Top = Image2.Top - 50
Image3.Top = Image3.Top - 50
Image4.Top = Image4.Top - 50
End Sub

 

posted @ 2014-05-29 20:36 jesonpeng 阅读(...) 评论(...) 编辑 收藏