红绿灯 vb

来源:百度知道 编辑:UC知道 时间:2024/05/11 00:06:24
Private Sub Form_Load()

m = 10
Label1.Caption = m
Timer2.Interval = 10000
Shape2.Visible = False

End Sub

Private Sub Timer2_Timer()
m = m - 1
Label1.Caption = m

If m = 0 Then m = 10

If Shape1.Visible = True Then
Shape2.Visible = True: Shape1.Visible = False

Else
Shape1.Visible = True: Shape1.Visible = False
If Shape2.Visible = True Then
Shape1.Visible = True: Shape2.Visible = False
Else
Shape1.Visible = True: Shape2.Visible = False
End If
End If
End Sub
我想如果红灯的时间只剩5秒的时候就一闪一闪的,绿灯也一样这样要怎么做,只要一个时间控件.

Private m As Integer

Private Sub Form_Load()
m = 40
Label1.Caption = m
Timer2.Interval = 500
Shape2.Visible = False

End Sub

Private Sub Timer2_Timer()
Static shine_bool As Boolean
shine_bool = Not shine_bool
m = m - 1
Label1.Caption = m

If m >= 30 Then
Shape1.Visible = True: Shape2.Visible = False
End If

If m < 30 And m >= 20 Then
If shine_bool Then
Shape1.Visible = False
Else
Shape1.Visible = True
End If
End If

If m >= 10 And m < 20 Then
Shape2.Visible = True: Shape1.Visible = False
End If

If m < 10 Then
If shine_bool Then
Shape2.Visible = False
Else
Shape2.Visible = True
End If
End If

If m = 0 Then m = 40
End Sub
为了闪烁速度快一点,我设置间隔为0.5s

在timer事件中不断更换红(绿)灯那个shape控件的visible属性。

再加