编写VB模拟交通信号灯
在窗体上做一个定时器控件,做一个Shape控件,复制后粘贴2次(回答“是”,即使用控件数组)。再使用以下的代码,就可以了:
Dim n As Integer
Private Sub Form_Load()
Timer1.Interval = 200
For i = 0 To 2
Shape1(i).Shape = 2
Shape1(i).FillStyle = 0
Next i
Shape1(0).FillColor = vbGreen
End Sub
Private Sub Timer1_Timer()
n = n + 1
If n = 60 Then n = 0
If n < 27 Then
Shape1(0).FillColor = vbGreen
Shape1(1).FillColor = &HC0C0C0
Shape1(2).FillColor = &HC0C0C0
Else
If n < 36 Then
If n Mod 3 < 2 Then
Shape1(0).FillColor = &HC0C0C0
Shape1(1).FillColor = vbYellow
Shape1(2).FillColor = &HC0C0C0
Else
Shape1(0).FillColor = &HC0C0C0
Shape1(1).FillColor = &HC0C0C0
Shape1(2).FillColor = &HC0C0C0
End If
Else
Shape1(0).FillColor = &HC0C0C0
Shape1(1).FillColor = &HC0C0C0
Shape1(2).FillColor = vbRed
End If
End If
End Sub
2024-12-19 广告
广告 您可能关注的内容 |