【实例说明】 在一个大型游戏载入内容的时候,都会有一个进度条来显示载入情况。
【编程思路】 利用Picture控件来覆盖另一个Picture控件。
【设计步骤】
1.新建一个标准工程,创建一个新窗体,默认名为Form1。
2.在窗体上放置三个CommandButton控件、一个Timer控件、Label控件和两个Picture控件。
3.源程序 [素材源程序下载]
Dim i As Integer
'开始
Private Sub Command1_Click()
If i < 100 Then
Timer1.Enabled = True
End If
End Sub
Private Sub Command2_Click()
If i < 100 Then
If Command2.Caption = "暂停" Then
Command2.Caption = "继续"
Timer1.Enabled = False
Label1.Caption = "暂停"
ElseIf Command2.Caption = "继续" Then
Command2.Caption = "暂停"
Timer1.Enabled = True
Label1.Caption = "已完成" & Str(i) & " " & "%"
End If
End If
End Sub
'退出
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
i = 0
Picture1.Top = Picture2.Top
Picture1.Height = Picture2.Height
Picture1.Left = Picture2.Left
Picture2.Width = 1
Picture2.BackColor = vbRed
Picture1.BackColor = vbBlack
Picture1.Width = 4000
Timer1.Interval = 100
Timer1.Enabled = False
Command2.Caption = "暂停"
End Sub
Private Sub Timer1_Timer()
If i < 100 Then
i = i + 1
Picture2.Width = i * 40
Label1.Caption = "已完成" & Str(i) & " " & "%"
ElseIf i = 100 Then
Me.Label1.Caption = "完毕"
Me.Timer1.Enabled = False
End If
End Sub
|