加一個(gè)計(jì)時(shí)器控件Timer1
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供古田網(wǎng)站建設(shè)、古田做網(wǎng)站、古田網(wǎng)站設(shè)計(jì)、古田網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、古田企業(yè)網(wǎng)站模板建站服務(wù),十載古田做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
代碼如下:
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后關(guān)閉.")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Dispose()
End Sub
畫面添加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
Dim?tCount?As?Integer?'用來計(jì)數(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("時(shí)間到")
Timer1.Enabled?=?False
End?If
End
Sub
1、程序加載時(shí)操作: Private Sub Form_Load() '窗體加載時(shí)自動(dòng)進(jìn)行
Timer1.Interval = 1000 ‘設(shè)置計(jì)時(shí)周期為1秒注意默認(rèn)計(jì)時(shí)單位為毫秒,即1/1000秒
2、定義一個(gè)時(shí)間變量??梢阅晨丶腃aption屬性代替,如Label12.Caption
3、拖放timer控件到程序界面上
4、設(shè)置倒計(jì)時(shí):雙擊時(shí)鐘控件,輸入計(jì)時(shí)規(guī)則,如Label12.Caption = Label12.Caption + 1
5、設(shè)置當(dāng)時(shí)間值達(dá)到某一條件的時(shí)候應(yīng)采取的方法(即動(dòng)作)??梢杂胕f語句。如if Label12.Caption =60,then Unload Form1,注意塊if語句與行if語句的區(qū)別
以下是例子:
Private Sub Form_Load() '窗體加載時(shí)自動(dòng)進(jìn)行以下操作
Timer1.Interval = 1000 '計(jì)時(shí)頻率設(shè)為1秒
end sub
Private Sub Timer1_Timer()
Label12.Caption = Label12.Caption - 1 '以秒計(jì)時(shí)
End Sub
Private Sub CommandSure_Click()
if Label12.Caption =
s = MsgBox("確認(rèn)提交,取消重填!", 1, "提示信息") '彈出對話框
If s = 1 Then
f = MsgBox("提交信息成功,請點(diǎn)擊確認(rèn)退出系統(tǒng)", 0, "")
Unload Form1 '窗體關(guān)閉
Else
Load Form1 '重新初始化
Form1.Enabled = True '允許重填
Timer1.Enabled = True '繼續(xù)計(jì)時(shí)
CommandSure.Enabled = True '確定按鈕可用
end if
end sub