实例说明
在本实例中,我们将制作一个具有交通灯效果的应用程序。程序运行后,交通灯不断地变化,可以通过按钮运行或停止程序。程序运行结果如图88-1所示。
技术要点
l 不断变换图片
l 不断更改时间间隔
实现过程
■ 新建项目
打开Visual Studio.NET,选择"新建项目",在项目类型窗口中选择"Visual Basic项目",在模板窗口中选择"Windows应用程序",在名称域中输入"Traffic",然后选择保存路径。单击"确认"。
■ 添加控件
向当前窗体添加一个Timer控件,用于控制交通灯变换的时间;三个Picture控件,分别装入相应的图片;一个Button按钮,用于控制交通灯。属性保持默认值。
Dim vv As Boolean
Dim updirec As Boolean
Private Sub Command1_Click(ByVal eventSender As System.Object,ByVal eventArgs As System.EventArgs) Handles Command1.Click
vv = Timer1.Enabled
vv = Not vv
Timer1.Enabled = vv
If vv Then
Command1.Text = "开 始"
Else
Command1.Text = "停 止"
End If
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object,ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
Static i As Short
Select Case i
Case 0
Timer1.Interval = 3000
picicon0.Visible = True
picicon1.Visible = False
picicon2.Visible = False
i = i + 1
updirec = False
Case 1
Timer1.Interval = 1000
picicon0.Visible = False
picicon1.Visible = True
picicon2.Visible = False
'Me.Icon = picicon(i).Image
If updirec Then
i = i - 1
Else
i = i + 1
End If
Case 2
Timer1.Interval = 3000
picicon0.Visible = False
picicon1.Visible = False
picicon2.Visible = True
i = i - 1
updirec = True
End Select
End Sub
■ 运行程序
单击菜单"调试|启动"或单击 图标运行程序。
小结
原文链接:https://www.f2er.com/vb/264277.html