Dim hour, min, sec As Integer
成都創(chuàng)新互聯(lián)2013年至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢想脫穎而出為使命,1280元天臺(tái)做網(wǎng)站,已為上家服務(wù),為天臺(tái)各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
Private Sub Command1_Click()
If Command1.Caption = "開始計(jì)時(shí)" Then
Command1.Caption = "停止計(jì)時(shí)"
Timer1.Enabled = True
Else
If Command1.Caption = "停止計(jì)時(shí)" Then
Command1.Caption = "開始計(jì)時(shí)"
Timer1.Enabled = False
End If
End If
End Sub
Private Sub Form_Load()
hour = 0
min = 0
sec = 0
Label1.Caption = Format(hour, "00") ":" Format(min, "00") ":" Format(sec, "00")
End Sub
Private Sub Timer1_Timer()
sec = sec + 1
If sec 59 Then
sec = 0
min = min + 1
If min 59 Then
min = 0
hour = hour + 1
End If
End If
Label1.Caption = ""
Label1.Caption = Format(hour, "00") ":" Format(min, "00") ":" Format(sec, "00")
End Sub
控制臺(tái)調(diào)用Timer和窗體是類似的。首先在項(xiàng)目引用里面加入System.Windows.Forms程序集,然后在代碼頂部引入命名空間:
Imports System.Windows.Forms
在控制臺(tái)的Module中聲明一個(gè)計(jì)時(shí)器:
Private WithEvents Timer1 As New Timer()
把計(jì)時(shí)器的Tick事件靜態(tài)綁定到處理函數(shù)中:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'一些代碼
End Sub
在需要開始計(jì)時(shí)的地方,修改其Interval、Enabled屬性:
Timer1.Interval = 1000
Timer1.Enabled = True
不對。步驟如下:
添加一個(gè)label標(biāo)簽名字label1 用來顯示時(shí)間
再添加一個(gè)timer控件 名字timer1 interval屬性=1000 用來計(jì)時(shí)
窗體添加代碼
Dim t As Date '用來記錄時(shí)間
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Timer1.Tick
t = t.AddSeconds(1)
Label1.Text = "登錄時(shí)間:" t.TimeOfDay.ToString
End Sub
用Timer控件吧,設(shè)置1秒執(zhí)行1次。然后直接在Timer中寫代碼,將全全局的值來
減減1,如果值為0,則停止Timer
跳出提示框
以下示例:
int
Tatal
=
100;
Timer.Inveral
=
1000;
Timer_()
{
if
(
Tatal
==
0)
{
MessageBox.Show("完成!");
Timer.Stop();
}
else
{
Tatal
--;
}
}
網(wǎng)頁題目:vb.net怎么寫計(jì)時(shí)器的簡單介紹
網(wǎng)站路徑:http://www.rwnh.cn/article12/phpegc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、網(wǎng)站改版、做網(wǎng)站、面包屑導(dǎo)航、網(wǎng)頁設(shè)計(jì)公司、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)