五笔打字通主页
VB程序题:设计一个带有进度条的倒计时程序,如图G.4所示。要求倒计时时间是以分为单位输入,以秒为单位显示,进度条指示的是倒数读秒的剩余时间,即填充块的数目随时间减少。
解题,如上图所示,在窗体上画2个按钮,一个标签控件,还要画一个计时器控件Timer1。相关的代码如下:
G4图:
Dim t As Single
Private Sub Command1_Click()
t = InputBox("输入倒计时分钟数")
t = t * 60
ProgressBar1.Min = 0
ProgressBar1.Max = t
ProgressBar1.Value = t
End Sub
Private Sub Command2_Click()
Timer1.Interval = 1000
ProgressBar1.Visible = True
End Sub
Private Sub Timer1_Timer()
Dim m%, s%
t = t - 1
ProgressBar1.Value = t
m = t \ 60
s = t Mod 60
Label1 = m & "分" & s & "秒"
If t = 0 Then
MsgBox "时间到!"
Timer1.Interval = 0
ProgressBar1.Visible = False
End If
End Sub
Visual Basic程序设计教程(第3版) (龚沛曾等编)课后实验源码
来源:济亨网
本文链接:http://wb86.com/post/102.html