要怎么用VB做红绿灯???

要怎么用VB做红绿灯???,第1张

Private Sub Form_Load()

Timer1.Enabled = True

Timer2.Enabled = True

Timer3.Enabled = False

End Sub

Private Sub Timer1_Timer()

For i = 0 To 3

Label1(i).Caption = Label1(i).Caption - 1

If Label1(i).Caption = -1 Then Label1(i).Caption = 60

Next

End Sub

Private Sub Timer2_Timer()

If Label1(1).Caption > 3 Then

Shape1.FillColor = vbGreen

Shape3.FillColor = vbGreen

Else

Shape1.FillColor = &H80FF&

Shape3.FillColor = &H80FF&

End If

Shape2.FillColor = vbRed

Shape4.FillColor = vbRed

If Label1(0).Caption = 0 Then Timer3.Enabled = True: Timer2.Enabled = False

End Sub

Private Sub Timer3_Timer()

If Label1(0).Caption > 3 Then

Shape2.FillColor = vbGreen

Shape4.FillColor = vbGreen

Else

Shape2.FillColor = &H80FF&

Shape4.FillColor = &H80FF&

End If

Shape1.FillColor = vbRed

Shape3.FillColor = vbRed

If Label1(0).Caption = 0 Then Timer2.Enabled = True: Timer3.Enabled = False

End Sub

Dim s As Integer

Dim n As Integer

'单击“红灯”按钮

Private Sub Command1_Click()

Shape6.Visible = True : Shape7.Visible = False : Shape8.Visible = False

End Sub

'单击“黄灯”按钮

Private Sub Command2_Click()

Shape6.Visible = False : Shape7.Visible = True : Shape8.Visible = False

End Sub

'单击“绿灯”按钮

Private Sub Command3_Click()

Shape6.Visible = False : Shape7.Visible = False : Shape8.Visible = True

End Sub

'单击“自动”按钮

Private Sub Command4_Click()

Timer1.Enabled = True

Command1.Enabled = False

Command2.Enabled = False

Command3.Enabled = False

n = 0 : s = 0

End Sub

'单击“手动”按钮

Private Sub Command5_Click()

Timer1.Enabled = False

Label1.Caption = ""

Shape6.Visible = False

Shape7.Visible = False

Shape8.Visible = False

Command1.Enabled = True

Command2.Enabled = True

Command3.Enabled = True

End Sub

'时钟控件启动

Private Sub Timer1_Timer()

Select Case n

Case 0

Shape6.Visible = True

Shape7.Visible = False

Shape8.Visible = False

Label1.Caption = 3 - s

s = s + 1

If s >3 Then

n = 1

s = 0

End If

Case 1

Shape6.Visible = False

Shape7.Visible = True

Shape8.Visible = False

n = 2

Case 2

Shape6.Visible = False

Shape7.Visible = False

Shape8.Visible = True

Label1.Caption = 3 - s

s = s + 1

If s >3 Then

n = 0 : s = 0

End If

End Select

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/11179661.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存