工程见附件:
在窗体上添加一个标签:Label1和一个Timer1控件。
完整代码如下:
Public Class Form1
Private ThisTime As Date '声明一个日期/时间变量
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = False '设置Timer1控件不能用
ThisTime = ThisTime.AddMinutes(2) '2分钟倒计时
Label1.Text = ThisTime '在标签里显示该时间
Timer1.Interval = 1000 '设置Timer1控件每秒触发一次
Timer1.Enabled = True '设置Timer1控件能用
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ThisTime = ThisTime.AddSeconds(-1) '设置变量减一秒钟
Label1.Text = ThisTime '在标签里显示该时间
If ThisTime = #12:00:00 AM# Then '如果变量为0,就结束倒计时,并提示!
Timer1.Enabled = False
MsgBox("OK!")
End If
End Sub
End Class
您好,Private Sub form_load()
Label1.Caption = 10
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Dim a
Label1.Caption = Label1.Caption - 1
If Label1.Caption = 0 Then
MsgBox "时间到!"
Unload Me
End If
End Sub