vb中如何利用计时控件设置红绿灯自动切换?
5个回答
展开全部
比如说red表示红灯图片,green表示绿灯图片,yellow表示黄灯图片,使用三个计时器控件,在属性窗口设其interval属性为30000,10000,30000(因为是毫秒计时的,这三个数字分别表示绿灯亮30秒,黄灯亮10秒,红灯亮30秒),然后则可以编写如下代码
private sub form_load() '开启一个计时器,并且显示绿灯
timmer1.enabled=true
timer2.enabled =false
timer3.enabled=false
green.visible=true
yello.visible=false
red.visible=false
end sub
private sub timer1_timer() '过30秒后显示黄灯
timmer1.enabled=false
timer2.enabled =true
timer3.enabled=false
green.visible=false
yello.visible=true
red.visible=false
end sub
private sub timer2_timer() ’过10秒显示红灯
timmer1.enabled=false
timer2.enabled =false
timer3.enabled=true
green.visible=false
yello.visible=false
red.visible=true
end sub
private sub timer3_timer() ,过30秒显示绿灯
timmer1.enabled=true
timer2.enabled =false
timer3.enabled=false
green.visible=true
yello.visible=false
red.visible=false
end sub
private sub form_load() '开启一个计时器,并且显示绿灯
timmer1.enabled=true
timer2.enabled =false
timer3.enabled=false
green.visible=true
yello.visible=false
red.visible=false
end sub
private sub timer1_timer() '过30秒后显示黄灯
timmer1.enabled=false
timer2.enabled =true
timer3.enabled=false
green.visible=false
yello.visible=true
red.visible=false
end sub
private sub timer2_timer() ’过10秒显示红灯
timmer1.enabled=false
timer2.enabled =false
timer3.enabled=true
green.visible=false
yello.visible=false
red.visible=true
end sub
private sub timer3_timer() ,过30秒显示绿灯
timmer1.enabled=true
timer2.enabled =false
timer3.enabled=false
green.visible=true
yello.visible=false
red.visible=false
end sub
展开全部
Dim I As Integer
Private Sub OBgreen_GotFocus()
Tred.Enabled = False
Tgreen.Enabled = True
Tyellow.Enabled = False
End Sub
Private Sub OBred_GotFocus()
Tgreen.Enabled = False
Tred.Enabled = True
Tyellow.Enabled = False
End Sub
Private Sub OByellow_GotFocus()
I = I + 1
Tred.Enabled = False
Tgreen.Enabled = False
Tyellow.Enabled = True
End Sub
Private Sub Tred_Timer()
OByellow.SetFocus
End Sub
Private Sub Tyellow_Timer()
If I Mod 2 = 1 Then
OBgreen.SetFocus
ElseIf I Mod 2 = 0 Then
OBred.SetFocus
End If
End Sub
Private Sub Tgreen_Timer()
OByellow.SetFocus
End Sub
Private Sub OBgreen_GotFocus()
Tred.Enabled = False
Tgreen.Enabled = True
Tyellow.Enabled = False
End Sub
Private Sub OBred_GotFocus()
Tgreen.Enabled = False
Tred.Enabled = True
Tyellow.Enabled = False
End Sub
Private Sub OByellow_GotFocus()
I = I + 1
Tred.Enabled = False
Tgreen.Enabled = False
Tyellow.Enabled = True
End Sub
Private Sub Tred_Timer()
OByellow.SetFocus
End Sub
Private Sub Tyellow_Timer()
If I Mod 2 = 1 Then
OBgreen.SetFocus
ElseIf I Mod 2 = 0 Then
OBred.SetFocus
End If
End Sub
Private Sub Tgreen_Timer()
OByellow.SetFocus
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim T As Integer
Private Sub Form_Load()
Shape1.Shape = 3
Shape2.Shape = 3
Shape3.Shape = 3
Shape1.BackStyle = 1
Shape2.BackStyle = 1
Shape3.BackStyle = 1
MD
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
T = T + 1
If T > 23 Then T = 0
If T < 10 Then
MD
Shape1.BackColor = &HFF
ElseIf T < 13 Then
MD
Shape2.BackColor = &HFFFF&
Else
MD
Shape3.BackColor = &HC000&
End If
End Sub
Private Sub MD()
Shape1.BackColor = &H808080
Shape2.BackColor = &H808080
Shape3.BackColor = &H808080
End Sub
Private Sub Form_Load()
Shape1.Shape = 3
Shape2.Shape = 3
Shape3.Shape = 3
Shape1.BackStyle = 1
Shape2.BackStyle = 1
Shape3.BackStyle = 1
MD
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
T = T + 1
If T > 23 Then T = 0
If T < 10 Then
MD
Shape1.BackColor = &HFF
ElseIf T < 13 Then
MD
Shape2.BackColor = &HFFFF&
Else
MD
Shape3.BackColor = &HC000&
End If
End Sub
Private Sub MD()
Shape1.BackColor = &H808080
Shape2.BackColor = &H808080
Shape3.BackColor = &H808080
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个不用问百度了,估计你没有看过微软的vb循序渐进教程这本书,里面有一个初学者课就是这个,有详细的代码,图片等等,在该书的配套光盘上有源代码。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Timer1_Timer()
Static i As Integer
If i = 0 Then
ShapeRed.Visible = True
ShapeYellow.Visible = False
ShapeGreen.Visible = False
i = 1
ElseIf i = 1 Then
ShapeRed.Visible = False
ShapeYellow.Visible = True
ShapeGreen.Visible = False
i = 2
ElseIf i = 2 Then
ShapeRed.Visible = False
ShapeYellow.Visible = False
ShapeGreen.Visible = True
i = 0
End If
End Sub
Static i As Integer
If i = 0 Then
ShapeRed.Visible = True
ShapeYellow.Visible = False
ShapeGreen.Visible = False
i = 1
ElseIf i = 1 Then
ShapeRed.Visible = False
ShapeYellow.Visible = True
ShapeGreen.Visible = False
i = 2
ElseIf i = 2 Then
ShapeRed.Visible = False
ShapeYellow.Visible = False
ShapeGreen.Visible = True
i = 0
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询