作者alumrof123e (alumrof123e)
看板Visual_Basic
标题Re: [.NET] 请问如何用Timer做红绿灯变换
时间Fri Nov 7 22:05:52 2008
※ 引述《humanfly (laguna)》之铭言:
: 1. 你会不会使用Timer ? 至少要了解 enabled & interval 两个属性
: 2. 你应该至少要用到一个counter
: 设interval=1000ms
: 每个tick counter+=1
: counter 1 2 3 4 5 6 7 8 9 10 11 12 13 14
: counter = 1~5 时 灯=红 , 读秒=counter
: counter = 6-8 时 灯=黄 , 读秒=counter -?
: counter = 9-14时 灯=绿 , 读秒=counter -?
: if counter= 14 後 再设counter=1
: 无限循环...
: 这是一种想法 GL
: ※ 引述《fjf1980 (VAIO才是NB的王道呀!)》之铭言:
: : 我要做一个练习题,可是想不到怎麽做。
: : 开一个form专案,然後在form上有红绿灯,旁边有数字读秒。
: : 红灯亮五秒,後黄灯亮三秒,後绿灯亮六秒。一直循环,亮的时候旁边读秒重新从1开始
: : 这应该要用Timer做吧! 但我想不到怎麽做。
: : 有没有高手能给点方向。 感谢!!
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
m = m + 1
Label2.Text = m
If m <= 5 Then
TextBox1.BackColor = Color.Red
c = c + 1
Label1.Text = c
If m = 5 Then c = 0
End If
If 5 < m And m <= 8 Then
TextBox1.BackColor = Color.Yellow
c = c + 1
Label1.Text = c
If m = 8 Then c = 0
End If
If 8 < m And m <= 14 Then
TextBox1.BackColor = Color.Green
c = c + 1
Label1.Text = c
If m = 14 Then c = 0
If m = 14 Then m = 0
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.124.68.58