vb.net計時器的簡單介紹
用VB.net做一個時間計時器
'添加一個label標簽名字label1 用來顯示時間
創新互聯長期為1000多家客戶提供的網站建設服務,團隊從業經驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯網生態環境。為山陰企業提供專業的成都網站建設、網站建設,山陰網站改版等技術服務。擁有10年豐富建站經驗和眾多成功案例,為您定制開發。
'再添加一個timer控件 名字timer1 interval屬性=1000 用來計時
'窗體添加代碼
Dim t As Date '用來記錄時間
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Timer1.Tick
t = t.AddSeconds(1)
Label1.Text = "登錄時間:" t.TimeOfDay.ToString
End Sub
VB.net module中如何使用計時器?
控制臺調用Timer和窗體是類似的。首先在項目引用里面加入System.Windows.Forms程序集,然后在代碼頂部引入命名空間:
Imports System.Windows.Forms
在控制臺的Module中聲明一個計時器:
Private WithEvents Timer1 As New Timer()
把計時器的Tick事件靜態綁定到處理函數中:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'一些代碼
End Sub
在需要開始計時的地方,修改其Interval、Enabled屬性:
Timer1.Interval = 1000
Timer1.Enabled = True
VB.net中如何用timer控件編出一個簡單的倒計時器?
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
vb.net 我想編一個計時器,計時器顯示格式00:00:00 (只能用一個label)怎么做?
Dim hour, min, sec As Integer
Private Sub Command1_Click()
If Command1.Caption = "開始計時" Then
Command1.Caption = "停止計時"
Timer1.Enabled = True
Else
If Command1.Caption = "停止計時" Then
Command1.Caption = "開始計時"
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
VB.NET 計時器的問題
不對。步驟如下:
添加一個label標簽名字label1 用來顯示時間
再添加一個timer控件 名字timer1 interval屬性=1000 用來計時
窗體添加代碼
Dim t As Date '用來記錄時間
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Timer1.Tick
t = t.AddSeconds(1)
Label1.Text = "登錄時間:" t.TimeOfDay.ToString
End Sub
網站題目:vb.net計時器的簡單介紹
標題鏈接:http://www.xueling.net.cn/article/dscpjcp.html