| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 786 人关注过本帖
标题:关于红绿灯交通模拟程序的一些问题,我有点困惑!
只看楼主 加入收藏
jack123son
Rank: 1
等 级:新手上路
帖 子:30
专家分:5
注 册:2011-10-8
结帖率:30%
收藏
 问题点数:0 回复次数:3 
关于红绿灯交通模拟程序的一些问题,我有点困惑!
大家帮我看看这个红绿灯交通模拟程序,里面的时间怎么设置才能正确呢?

我想模仿现实生活中的十字路口的红绿灯程序,但是时间我把握不好,希望能得到高人的指点!我用的是Visual Studio 2005!


Public Class Form1

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick '每2秒钟显示绿灯
        PictureBox1.Visible = False '红灯不亮
        PictureBox3.Visible = False '红灯不亮
        PictureBox2.Visible = True '绿灯亮
        PictureBox4.Visible = True '绿灯亮
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = False
        Timer1.Interval = 2000
        Timer2.Interval = 7000
        Timer2.Enabled = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Enabled = True
        Timer2.Enabled = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = False
        Timer2.Enabled = False
        PictureBox1.Visible = True
        PictureBox2.Visible = True
        PictureBox3.Visible = True
        PictureBox4.Visible = True
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick '每7秒钟显示红灯
        PictureBox1.Visible = True
        PictureBox3.Visible = True
        PictureBox2.Visible = False
        PictureBox4.Visible = False

    End Sub
End Class

我还想问问,这个论坛怎么都不能上传附件了呢?图片也不能上传啊?
搜索更多相关主题的帖子: 红绿灯 交通 False 
2012-05-29 21:32
wumingchenxi
Rank: 6Rank: 6
等 级:侠之大者
威 望:6
帖 子:96
专家分:457
注 册:2012-6-6
收藏
得分:0 
你现在的效果是基本都是绿的,偶尔1,2秒是红的?
如果用时间标尺分析
第2秒 Timer1_Tick 绿,
第4秒 Timer1_Tick 绿,
第6秒 Timer1_Tick 绿,
第7秒 Timer2_Tick 红,
第8秒 Timer1_Tick 绿,
第10秒 Timer1_Tick 绿,
第12秒 Timer1_Tick 绿,
第14秒 Timer1_Tick 绿,Timer2_Tick 红,理论上说timer1先enabled,应该先执行,不过timer1已经执行了好几次,会不会造成时间后延,就要看系统了。

如果说要模拟红绿灯,就不能说每2秒显示绿,每7秒显示红,应该说绿的延续2秒,切换成红的,延续7秒。
只要一个Timer
              

dim CurrentisGreen=false
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick '每2秒钟显示绿灯
 if CurrentisGreen  then
     Timer1.Interval = 2000
     CurrentisGreen=false      //为下次执行做准备
    PictureBox1.Visible = False '红灯不亮
    PictureBox3.Visible = False '红灯不亮
    PictureBox2.Visible = True '绿灯亮
    PictureBox4.Visible = True '绿灯亮
else
     Timer1.Interval = 7000
     CurrentisGreen=true    //为下次执行做准备
    PictureBox1.Visible = True '红灯亮
    PictureBox3.Visible = True '红灯亮
    PictureBox2.Visible = False '绿灯不亮
    PictureBox4.Visible = False '绿灯不亮
 
end if
 
End Sub
 
2012-06-07 12:03
g12339645
Rank: 2
等 级:论坛游民
帖 子:14
专家分:42
注 册:2011-6-17
收藏
得分:0 
Timer1的interval不变行不行?
2012-06-22 18:11
沉默吧ljh
Rank: 2
来 自:河北唐山
等 级:论坛游民
帖 子:5
专家分:20
注 册:2012-6-15
收藏
得分:0 
   刚按错键了 莫怪 我再想想

[ 本帖最后由 沉默吧ljh 于 2012-6-25 23:16 编辑 ]
2012-06-25 22:43
快速回复:关于红绿灯交通模拟程序的一些问题,我有点困惑!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014961 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved