VB定时器控制小图形上下移动

来源:百度知道 编辑:UC知道 时间:2024/09/18 07:15:50
下面是我写的代码,让图形在600-2400之间不停地动,不知有什么错误

Private Sub Timer1_Timer() '向下
If Shape1.Top = 600 Then Timer2.Enabled = False: Timer1.Enabled = True
Shape1.Top = Shape1.Top + 200
End Sub

Private Sub Timer2_Timer() '向上
If Shape1.Top = 2400 Then Timer1.Enabled = False: Timer2.Enabled = True
Shape1.Top = Shape1.Top - 200

End Sub
开心的贝壳 的方法不行

Option Explicit
Dim A As Boolean

Private Sub Timer1_Timer()
If A = False Then
Shape1.Top = Shape1.Top + 200
If Shape1.Top > 2400 Then
A = True
End If
Else
Shape1.Top = Shape1.Top - 200
If Shape1.Top < 600 Then
A = False
End If
End If
End Sub

用这种方法吧!省了一个定时器!

Private Sub Timer1_Timer() '向下
Shape1.Top = Shape1.Top + 200
If Shape1.Top > 2400 Then
Timer1.Enabled = False
Timer2.Enabled = True
End If
End Sub

Private Sub Timer2_Timer() '向上
Shape1.Top = Shape1.Top - 200
If Shape1.Top < 600 Then
Timer1.Enabled = True
Timer2.Enabled = False
End If

End Sub

看看我的代码 改改就可以
Option Explicit
Public i As Boolean
Public k As Boolean
Private Sub Timer1_Timer()
If shape1.Top > 0 And i = False Then
Call updown(shape1, -5)
Else
If sh