怎么用VB做这个交通灯
一个图片框,一个定时器,图片框里在添加一个文本标签
代码如下:
Dim zt As Long, js As Long
Function xshld(ByVal cl As Integer, sj As Integer)
Label2.Visible = True
Form1.Picture1.FillStyle = 0 '设定填充模式为实心
If cl = 1 Then
Label2.Top = 250
Label2.BackColor = vbRed
Form1.Picture1.FillColor = vbRed
Else
Form1.Picture1.FillColor = vbBlack
End If
Form1.Picture1.Circle (700, 700), 600, vbRed
If cl = 2 Then
Label2.Top = 1750
Label2.BackColor = vbYellow
Form1.Picture1.FillColor = vbYellow
Else
Form1.Picture1.FillColor = vbBlack
End If
Form1.Picture1.Circle (700, 2100), 600, vbYellow
If cl = 3 Then
Label2.Top = 3050
Label2.BackColor = vbGreen
Form1.Picture1.FillColor = vbGreen
Else
Form1.Picture1.FillColor = vbBlack
End If
Form1.Picture1.Circle (700, 3500), 600, vbGreen
If sj < 10 Then
Label2.Left = 500
Else
Label2.Left = 300
End If
Label2.Caption = sj
End Function
Private Sub Form_Load()
Label2.FontSize = 40
Label2.Caption = "30"
Label2.Top = 250
Label2.Left = 300
Label2.ForeColor = vbWhite
Form1.Picture1.BackColor = vbBlack
Label2.Visible = False
Me.Caption = "交通灯"
End Sub
Private Sub Timer1_Timer()
If zt = 0 Then
Call xshld(1, 30 - js)
js = js + 1
If js >= 30 Then
Label2.Visible = False
zt = 1
js = 0
End If
End If
If zt = 1 Then
Call xshld(2, 10 - js)
js = js + 1
If js >= 10 Then
Label2.Visible = False
zt = 2
js = 0
End If
End If
If zt = 2 Then
Call xshld(3, 30 - js)
js = js + 1
If js >= 30 Then
Label2.Visible = False
zt = 0
js = 0
End If
End If
End Sub