准备3张图片:
工程窗口中加入一个Picture1,在Picture1中增加一个Label1,在窗口中增加一个定时器Timer1
运行情况:
程序代码:
Dim zt As Long, js As Long
Private Sub Form_Load()
Me.Caption = "交通灯"
zt = 0
js = 0
Label1.ZOrder 0
Label1.Top = 250
Label1.FontSize = 40
Label1.ForeColor = vbWhite
End Sub
Function xsjtd(ByVal cl As String, ByVal sz As Integer)
Me.Picture1.Picture = VB.LoadPicture(App.Path & "\" & cl & ".jpg")
If sz < 10 Then
Label1.Left = 480
Else
Label1.Left = 240
End If
If cl = "红" Then
Label1.Top = 250
ElseIf cl = "黄" Then
Label1.Top = 1750
Else
Label1.Top = 3250
End If
Label1.Caption = sz
End Function
Private Sub Timer1_Timer()
Dim n As Integer
If zt = 0 Then
js = js + 1
n = 30 - js
Call xsjtd("红", n)
If js >= 30 Then
zt = 1
js = 0
Exit Sub
End If
End If
If zt = 1 Then
js = js + 1
n = 10 - js
Call xsjtd("黄", n)
If js >= 10 Then
zt = 2
js = 0
Exit Sub
End If
End If
If zt = 2 Then
js = js + 1
n = 30 - js
Call xsjtd("绿", n)
If js >= 30 Then
zt = 0
js = 0
Exit Sub
End If
End If
End Sub
2024-12-05 广告
不过这也很简单,你可以用,
public 定义全局变量来处理
倒计时变量。