关于一道VB模拟考试题,高手帮忙做下呀!
这是一道上机编程的题:有三个图片框,里面分别是红色,绿色,黄色,用来代表道路上的红绿灯。用timer控件来实现它们的闪烁效果。要求,红色,绿色,黄色分别亮起(即是红灯亮而...
这是一道上机编程的题:
有三个图片框,里面分别是红色,绿色,黄色,用来代表道路上的红绿灯。用timer控件来实现它们的闪烁效果。要求,红色,绿色,黄色分别亮起(即是红灯亮而绿黄灯不亮,依此类推)
高手谢谢啦 展开
有三个图片框,里面分别是红色,绿色,黄色,用来代表道路上的红绿灯。用timer控件来实现它们的闪烁效果。要求,红色,绿色,黄色分别亮起(即是红灯亮而绿黄灯不亮,依此类推)
高手谢谢啦 展开
2个回答
展开全部
'在窗体上建一个timer,3个图片框,复制以下代码即可:
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 3000'设置间隔时间为3秒
End Sub
Private Sub Timer1_Timer()
Static i As Integer
i = i + 1
If i = 1 Then Picture1.BackColor = vbRed: Picture2.BackColor = Me.BackColor: Picture3.BackColor = Me.BackColor
If i = 2 Then Picture1.BackColor = Me.BackColor: Picture2.BackColor = vbGreen: Picture3.BackColor = Me.BackColor
If i = 3 Then Picture1.BackColor = Me.BackColor: Picture2.BackColor = Me.BackColor: Picture3.BackColor = vbYellow
If i >= 3 Then i = 0
End Sub
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 3000'设置间隔时间为3秒
End Sub
Private Sub Timer1_Timer()
Static i As Integer
i = i + 1
If i = 1 Then Picture1.BackColor = vbRed: Picture2.BackColor = Me.BackColor: Picture3.BackColor = Me.BackColor
If i = 2 Then Picture1.BackColor = Me.BackColor: Picture2.BackColor = vbGreen: Picture3.BackColor = Me.BackColor
If i = 3 Then Picture1.BackColor = Me.BackColor: Picture2.BackColor = Me.BackColor: Picture3.BackColor = vbYellow
If i >= 3 Then i = 0
End Sub
展开全部
假如你使用Picture控件来存放颜色图片
PictureRED PictureGreen PictureBLUE
dim a as Long
Private Sub Timer1_Timer()
If a Mod 3 = 1 Then
PictureBLUE.Visible = True
PictureRED.Visible = False
PictureGREEN.Visible = False
ElseIf a Mod 3 = 2 Then
PictureRED.Visible = True
PictureGREEN.Visible = False
PictureBLUE.Visible = False
Else
PictureGREEN.Visible = True
PictureBLUE.Visible = False
PictureRED.Visible = False
End If
a = a + 1
If a > 100000 Then
a = 0
End If
End Sub
PictureRED PictureGreen PictureBLUE
dim a as Long
Private Sub Timer1_Timer()
If a Mod 3 = 1 Then
PictureBLUE.Visible = True
PictureRED.Visible = False
PictureGREEN.Visible = False
ElseIf a Mod 3 = 2 Then
PictureRED.Visible = True
PictureGREEN.Visible = False
PictureBLUE.Visible = False
Else
PictureGREEN.Visible = True
PictureBLUE.Visible = False
PictureRED.Visible = False
End If
a = a + 1
If a > 100000 Then
a = 0
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询