画面添加textbox1 timer1
创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站设计、网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的冠县网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 1000
TextBox1.Text = "2011/12/07 10:35:00"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If IsDate(TextBox1.Text) = True Then
Timer1.Start()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Format(Now, "yyyy/MM/dd hh:mm:ss") = TextBox1.Text Then
MsgBox("It's time to go")
Timer1.Stop()
End If
End Sub
'Timer1,Label1,Label2,Text1,cmdstar
Dim lngTime As Long
Private Sub cmdstar_Click()
If Not IsNumeric(Text1.Text) Then
MsgBox "请输入一个正整数", vbOKOnly, "输入"
Exit Sub
End If
lngTime = Val(Text1.Text) * 600
Timer1.Enabled = True
Call Timer1_Timer
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = False
Text1.Text = "3"
Label1.AutoSize = True
Label1.Caption = ""
Label2.AutoSize = True
Label2.Caption = ""
End Sub
Private Sub Timer1_Timer()
lngTime = lngTime - 1
Label1.Caption = "还剩:" Format(lngTime \ 600, "00:") Format((lngTime Mod 600) \ 10, "00 分")
Label2.Caption = "还剩:" Format(lngTime \ 10, "00.") Format(lngTime Mod 10, "0 秒")
If lngTime = 0 Then
Timer1.Enabled = False
MsgBox "时间到"
End If
End Sub
加一个计时器控件Timer1
代码如下:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Interval = 15000
Timer1.Start()
MessageBox.Show("程序将在15s后关闭.")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Dispose()
End Sub
Dim tCount As Integer '用来计数
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
tCount = 10
Timer1.Interval = 1000 '每秒执行一次
Timer1.Enabled = True
End
Sub
Private Sub
Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
tCount -= 1
If tCount = 0 Then
MessageBox.Show("时间到")
Timer1.Enabled = False
End If
End
Sub
窗体中增加timer1控件,Interval设为1000(即1秒),enabled=false
添加Label1控件,初始值设为60
添加button1控件,标题=“开始倒计时”
button1.click事件下编写timer1.enabled=true'开始倒计时
Timer1_Timer(vb6)或Timer1_Tick(vb.net)事件下编写
Label1.Caption=val(Label1.Caption)-1'(vb6)
或者Label1.Text=val(Label1.Text)-1'(vb.net)
在30秒的时候弹出个messagebox选择的事件
确定就把timer的enabled属性设置成false 执行关机
取消把timer的enabled属性设置成false 计时器清零就行了