1、 在桌面上,鼠标左键双击,打开VB编程软件,在左边工具栏上单击Image按钮,在Form1窗口上,绘制出图框,然后在Image属性面板的Picture属性上,单击【加载图片】按钮。
2、 接着,在d出选取图片对话框,选择合适的红绿灯素材来体现效果,这里先选取了一张红灯的图片。
3、在Image属性面板的名称属性上,将其改名为red,标识后就不会与其他图混淆。
4、在VB编程的界面中也可以直接复制控件,如将red这个Image控件复制两个出来,不加入控件组,并将后两个依次改名为yellow、green。
5、 然后,将yellow图形控件与red控件重叠,并右键单击,在d出的菜单中选择【移至底层】,放好后,green 图形控件放在最底层。三个图形控件依红、黄、绿的顺序叠加重合了。
6、接着,鼠标左键双击red图形控件,d出输入代码窗口,在其上输入如下代码段。
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
Option ExplicitDim T As Integer
Private Sub Form_Load()
Label1.Caption = "绿灯行"
Label1.ForeColor = vbGreen
Shape1.Shape = 3
Shape1.FillStyle = 0
Shape1.FillColor = vbGreen
Label1.ForeColor = vbGreen
Label1.FontSize = 18
Timer1.Interval = 1000
T = 0
End SubPrivate Sub Timer1_Timer()
T = T + 1
Select Case T
Case 1 To 3:
Shape1.FillColor = vbGreen
Label1.Caption = "绿灯行"
Label1.ForeColor = vbGreen
Shape1.Shape = 3
Case 4 To 5:
Shape1.FillColor = vbYellow
Label1.ForeColor = vbYellow
Label1.Caption = "注意"
Case 6 To 8:
Shape1.FillColor = vbRed
Label1.ForeColor = vbRed
Label1.Caption = "红灯停"
Case 9 To 10:
Shape1.FillColor = vbYellow
Label1.ForeColor = vbYellow
Label1.Caption = "注意"
T = 0
End Select
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)