使用vb设计倒计时的程序代码

来源:百度知道 编辑:UC知道 时间:2024/05/26 21:38:05
* 界面要求:
* 使用标签,文本框,命令按钮、时钟控件完成。
* 运行要求:
* 用户点击“开始”按钮,从文本框中读取初始秒数显示到上面的标签中,每隔一秒将标签中,显示的秒数减1,当减到0时,将时钟控件的Enbabled属性置为False,并使用MsgBox显示“时间到

Private Sub Command1_Click()
Label1.Caption = Text1.Text
Timer1.Enabled = True
End Sub

Private Sub Form_Load()

Timer1.Interval = 1000

End Sub

Private Sub text1_KeyPress(KeyAscii As Integer) 'text内只能输入数字

Select Case KeyAscii
Case 48 To 57 '0-9
Exit Sub
Case Else
KeyAscii = 0
End Select
End Sub

Private Sub Timer1_Timer()
Label1.Caption = Str(Val(Label1.Caption) - 1)
If Val(Label1.Caption) = 0 Then
MsgBox "时间到"
Timer1.Enabled = False
End If
End Sub

Dim i As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 1000
Label1.AutoSize = True
i = Val(Text1.Text)
End Sub

Private Sub Timer1_Timer()
Label1.Caption = i
If i = 0 Then
MsgBox "时间到"
Timer1.Enabled = False
End If
i = i - 1
End Sub