作者humanfly (laguna)
看板Visual_Basic
标题Re: [.NET] 请问如何用Timer做红绿灯变换
时间Wed Nov 5 09:58:06 2008
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做吧! 但我想不到怎麽做。
: 有没有高手能给点方向。 感谢!!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.117.128.13
1F:推 fjf1980:我只有看过书上练习的蟑螂爬还有连绪跳动的球,timer其实 11/05 10:36
2F:→ fjf1980:还没很会使用 >"<。 11/05 10:37
3F:→ humanfly:好了,工具箱+一个timer 进去,form_load 写 11/05 18:13
4F:→ humanfly:timer1.enable=true timer1.interval=1000 11/05 18:14
5F:→ humanfly:然後timer1点两下 在timer1_tick 里写你的程式 11/05 18:15