畫面添加textbox1 timer1
創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務領域包括:網(wǎng)站設計、網(wǎng)站建設、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的冠縣網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!
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 "請輸入一個正整數(shù)", 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("程序?qū)⒃?5s后關閉.")
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?'用來計數(shù)
Private?Sub?Form1_Load(ByVal?sender?As?System.Object,?ByVal?e?As
System.EventArgs)?Handles?MyBase.Load
tCount?=?10
Timer1.Interval?=?1000?'每秒執(zhí)行一次
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 執(zhí)行關機
取消把timer的enabled屬性設置成false 計時器清零就行了