[VB.NET]旋转月亮

前端之家收集整理的这篇文章主要介绍了[VB.NET]旋转月亮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
旋转月亮

实例说明

在本实例中,我们将制作一个具有"旋转月亮"功能的应用程序。程序运行后,单击"开始演示"按钮,即可开始旋转月亮。此时按钮标题会变为"停止演示"。再单击该按钮,则停止旋转月亮。程序运行结果如图74-1所示。

图74-1 运行结果

技术要点

l Timer控件

l 显示/隐藏图片

实现过程

■ 新建项目

打开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

MsgBox("错误!")

End Select

i = i + 1

If i > 9 Then

i = 1

End If

End Sub

■ 运行程序

单击菜单"调试|启动"或单击 图标运行程序。

小结

本实例是通过显示不同的图片来达到旋转月亮的效果。由于在VB.NET中没有了控件数组,因此我们只能分别隐藏和显示

原文链接:https://www.f2er.com/vb/264289.html

猜你在找的VB相关文章