实例说明
在本实例中,我们将制作一个具有"旋转月亮"功能的应用程序。程序运行后,单击"开始演示"按钮,即可开始旋转月亮。此时按钮标题会变为"停止演示"。再单击该按钮,则停止旋转月亮。程序运行结果如图74-1所示。
图74-1 运行结果
技术要点
l Timer控件
实现过程
■ 新建项目
打开Visual Studio.NET,选择"新建项目",在项目类型窗口中选择"Visual Basic项目",在模板窗口中选择"Windows应用程序",在名称域中输入"SpinMoon",然后选择保存路径。单击"确认"。
■ 添加控件
向窗体上添加一个Button控件和九个Picture控件。
■ 设置属性
将Button控件的Text设置为"开始演示",将Picture控件的名称改为imgMoon1-imgMoon9,并装入相应的图片。
Dim i As Short
Private Sub Command1_Click(ByVal eventSender As System.Object,ByVal eventArgs As System.EventArgs) Handles Command1.Click
If Command1.Text = "开始演示" Then
Command1.Text = "停止演示"
Timer1.Enabled = True
Else
Command1.Text = "开始演示"
Timer1.Enabled = False
End If
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object,ByVal eventArgs As System.EventArgs) Handles MyBase.Load
i = 1
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object,ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
Select Case i
Case 1
imgMoon1.Visible = True
imgMoon3.Visible = False
imgMoon4.Visible = False
imgMoon5.Visible = False
imgMoon6.Visible = False
imgMoon7.Visible = False
imgMoon8.Visible = False
imgMoon9.Visible = False
Case 2
imgMoon1.Visible = False
imgMoon2.Visible = True
imgMoon3.Visible = False
imgMoon4.Visible = False
imgMoon5.Visible = False
imgMoon6.Visible = False
imgMoon7.Visible = False
imgMoon8.Visible = False
imgMoon9.Visible = False
Case 3
imgMoon1.Visible = False
imgMoon2.Visible = False
imgMoon3.Visible = True
imgMoon4.Visible = False
imgMoon5.Visible = False
imgMoon6.Visible = False
imgMoon7.Visible = False
imgMoon8.Visible = False
imgMoon9.Visible = False
………………中间代码省略……………………
Case 9
imgMoon1.Visible = False
imgMoon2.Visible = False
imgMoon3.Visible = False
imgMoon4.Visible = False
imgMoon5.Visible = False
imgMoon6.Visible = False
imgMoon7.Visible = False
imgMoon8.Visible = False
imgMoon9.Visible = True
Case Else
End Select
i = i + 1
If i > 9 Then
i = 1
End If
End Sub
■ 运行程序
单击菜单"调试|启动"或单击 图标运行程序。
小结
原文链接:https://www.f2er.com/vb/264289.html