怎么在vb中编写弄个timer控件,每秒减一,当=0时,秒数回到10,并且红绿灯换颜色
展开全部
在窗体中做一个Shape控件,复制后粘贴2次,做控件数组。
再做一个定时器控件,然后是以下的代码:
Dim n As Integer
Private Sub Form_Load()
n = 10
Timer1.Interval = 1000
For i = 0 To 2
Shape1(i).Shape = 2
Shape1(i).FillStyle = 0
Next i
Shape1(0).FillColor = vbGreen
End Sub
Private Sub Timer1_Timer()
n = n - 1
If n = 0 Then n = 10
If n > 6 Then
Shape1(0).FillColor = vbGreen
Shape1(1).FillColor = &HC0C0C0
Shape1(2).FillColor = &HC0C0C0
Else
If n > 2 Then
If n Mod 3 < 2 Then
Shape1(0).FillColor = &HC0C0C0
Shape1(1).FillColor = vbYellow
Shape1(2).FillColor = &HC0C0C0
Else
Shape1(0).FillColor = &HC0C0C0
Shape1(1).FillColor = &HC0C0C0
Shape1(2).FillColor = &HC0C0C0
End If
Else
Shape1(0).FillColor = &HC0C0C0
Shape1(1).FillColor = &HC0C0C0
Shape1(2).FillColor = vbRed
End If
End If
End Sub
再做一个定时器控件,然后是以下的代码:
Dim n As Integer
Private Sub Form_Load()
n = 10
Timer1.Interval = 1000
For i = 0 To 2
Shape1(i).Shape = 2
Shape1(i).FillStyle = 0
Next i
Shape1(0).FillColor = vbGreen
End Sub
Private Sub Timer1_Timer()
n = n - 1
If n = 0 Then n = 10
If n > 6 Then
Shape1(0).FillColor = vbGreen
Shape1(1).FillColor = &HC0C0C0
Shape1(2).FillColor = &HC0C0C0
Else
If n > 2 Then
If n Mod 3 < 2 Then
Shape1(0).FillColor = &HC0C0C0
Shape1(1).FillColor = vbYellow
Shape1(2).FillColor = &HC0C0C0
Else
Shape1(0).FillColor = &HC0C0C0
Shape1(1).FillColor = &HC0C0C0
Shape1(2).FillColor = &HC0C0C0
End If
Else
Shape1(0).FillColor = &HC0C0C0
Shape1(1).FillColor = &HC0C0C0
Shape1(2).FillColor = vbRed
End If
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询