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

2024-11-25 02:46:00
推荐回答(2个)
回答1:

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

回答2:

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