请问这道VB题怎么做??
(1)程序刚运行时,红灯亮,倒计时时间为10秒;
(2)点击“开始”按钮后,开始倒计时,红灯到时变为黄灯,黄灯到时变为绿灯,绿灯到时变为黄灯,黄灯到时变为红灯,以此循环。
(3)红灯和绿灯的倒计时为10秒,黄灯的倒计时是为3秒。
(4)不同颜色的灯亮时,倒计时的数字显示为相应的颜色。
(5)点击“暂停”按钮,停止倒计时。 展开
准备3张图片,分别是红灯亮,黄灯亮和绿灯亮时的图片!,在窗口中拖入一个timer控件,一个图片控件,2个按钮,一个标签!
在timer事件中编写代码就好了!
Dim n As Long, m As Long
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
n = 10
m = 0 '0代表红灯亮,1代表黄灯亮,2代表绿灯亮
Picture1.Picture = VB.LoadPicture("c:\红灯亮.jpg")
Label1.AutoSize = True
Label1.Font.Size = 24
Label1.Caption = n
Label1.ForeColor = vbRed
Me.Caption = "模拟交通灯"
Command1.Caption = "开始"
Command2.Caption = "暂停"
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
If m = 0 Then
If n = 10 Then
Picture1.Picture = VB.LoadPicture("c:\红灯亮.jpg")
End If
Label1.Caption = n
Label1.ForeColor = vbRed
n = n - 1
If n = 0 Then
m = 1
n = 3
End If
Exit Sub
End If
If m = 1 Then
If n = 3 Then
Picture1.Picture = VB.LoadPicture("c:\黄灯亮.jpg")
End If
Label1.Caption = n
Label1.ForeColor = vbYellow
n = n - 1
If n = 0 Then
m = 2
n = 10
End If
Exit Sub
End If
If m = 2 Then
If n = 10 Then
Picture1.Picture = VB.LoadPicture("c:\绿灯亮.jpg")
End If
Label1.Caption = n
Label1.ForeColor = vbGreen
n = n - 1
If n = 0 Then
m = 0
n = 10
End If
Exit Sub
End If
End Sub