用VB.NET编写红绿灯程序给你思路把:当汽车运动时 , 他的left和top和right(left width)和bottom(top height)碰到红绿灯的范围 , 就停止汽车运动的那个计时器,并将另一个计时器的时间设为延时秒数并开启 , 里面的代码是打开骑车运动的计时器 。
VB编程设计题:红绿灯如图在窗体上添加:
1、四个shape控件,作为灯框、红灯、黄灯、绿灯,分别命名为:LampBox、RedLamp、YellowLamp、GreenLamp
2、一个命令按钮 , 命名为:cmdRun,标题为“启动”
3、三个文本框控件 , 来设置红灯、黄灯、绿灯亮的时间(秒) , 分别命名为:txtRedTime、txtYellowTime、txtGreenTime
4、四个时钟控件,作为红灯、黄灯、绿灯和闪烁时间控制,分别命名为:tmrRed、tmrYellow、tmrGreen、tmrChange
5、其它控件和布局见图
程序如下:
Private Red As Long
Private Yellow As Long
Private Green As Long
Private Black As Long
Private LampNo As Integer
Private Sub cmdRun_Click()
If cmdRun.Caption = "启动" Then
txtRedTime.Enabled = False
txtYellowTime.Enabled = False
txtGreenTime.Enabled = False
cmdRun.Caption = "停止"
tmrRed.Interval = Val(txtRedTime.Text) * 1000
tmrYellow.Interval = Val(txtYellowTime.Text) * 1000
tmrGreen.Interval = Val(txtGreenTime.Text) * 1000
LampNo = 0
tmrChange.Enabled = True
Else
tmrRed.Enabled = False
tmrYellow.Enabled = False
tmrGreen.Enabled = False
tmrChange.Enabled = False
RedLamp.FillColor = Black
YellowLamp.FillColor = Black
GreenLamp.FillColor = Black
txtRedTime.Enabled = True
txtYellowTime.Enabled = True
txtGreenTime.Enabled = True
cmdRun.Caption = "启动"
End If
End Sub
Private Sub Form_Load()
tmrRed.Enabled = False
tmrYellow.Enabled = False
tmrGreen.Enabled = False
tmrChange.Enabled = False
Red = HFF
Yellow = HFFFF
Green = HFF00
Black = H0
LampBox.FillColor = Black
RedLamp.FillColor = Black
YellowLamp.FillColor = Black
GreenLamp.FillColor = Black
tmrChange.Interval = 300
txtRedTime.Text = 6
txtYellowTime.Text = 1
txtGreenTime.Text = 8
End Sub
Private Sub tmrChange_Timer()
Static n As Integer
n = n1
Select Case LampNo
Case 0
If RedLamp.FillColor = Black Then
RedLamp.FillColor = Red
YellowLamp.FillColor = Yellow
GreenLamp.FillColor = Green
Else
RedLamp.FillColor = Black
YellowLamp.FillColor = Black
GreenLamp.FillColor = Black
End If
Case 1
If RedLamp.FillColor = Black Then
RedLamp.FillColor = Red
Else
RedLamp.FillColor = Black
End If
Case 2
YellowLamp.FillColor = Yellow
Case 3
If GreenLamp.FillColor = Black Then
GreenLamp.FillColor = Green
Else
GreenLamp.FillColor = Black
End If
End Select
If n = 4 Then
n = 0
LampNo = LampNo1
If LampNo = 5 Then LampNo = 1
Select Case LampNo
Case 1
RedLamp.FillColor = Red
YellowLamp.FillColor = Black
GreenLamp.FillColor = Black
tmrRed.Enabled = True
Case 2, 4
RedLamp.FillColor = Black
YellowLamp.FillColor = Yellow
GreenLamp.FillColor = Black
tmrYellow.Enabled = True
Case 3
RedLamp.FillColor = Black
YellowLamp.FillColor = Black
GreenLamp.FillColor = Green
tmrGreen.Enabled = True
End Select
tmrChange.Enabled = False
End If
End Sub
Private Sub tmrGreen_Timer()
tmrChange.Enabled = True
tmrGreen.Enabled = False
End Sub
Private Sub tmrRed_Timer()
tmrChange.Enabled = True
tmrRed.Enabled = False
End Sub
Private Sub tmrYellow_Timer()
tmrChange.Enabled = True
tmrYellow.Enabled = False
End Sub
用VB.net模拟十字路口红绿灯交通信号的切换实在不难,就是不知道你写了代码没有?
答案补充:
Dim xuhao As Integer
Const wenjianjia = "" '自己写好了
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
xuhao = xuhao1
If xuhao = 4 Then xuhao = 1
Picture1.Picture = LoadPicture(wenjianjia"\"xuhao".ico")
End Sub
自动挡小汽车过红绿灯时应该怎么办?红灯停、绿灯行vb.net小车过红绿灯;
自动挡汽车vb.net小车过红绿灯 , 遇到红灯vb.net小车过红绿灯,前行到合适位置,踩刹车停车,红灯变绿灯后,松刹车,加油门,继续前行 。
【vb.net小车过红绿灯 vb红绿灯代码】vb.net小车过红绿灯的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于vb红绿灯代码、vb.net小车过红绿灯的信息别忘了在本站进行查找喔 。
推荐阅读
- 安卓模拟器模拟苹果客户端,安卓模拟器模拟苹果客户端下载
- 系统工具下载,系统工具包怎么用
- 经典第一人称射击类游戏,第一人称射击游戏大作
- java解决高并发代码 java高并发问题
- 百度云接口phpcms,百度云接口网址
- 经典角色动作单机游戏,经典角色动作单机游戏大全
- 音乐直播带货教程视频,音乐类直播
- 不定参数函数python 不定参数函数怎么理解
- 安卓微信朋友圈照片乱码,安卓微信一键转发朋友圈