vb.net线程计时器的简单介绍

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 = sec1
If sec59 Then
sec = 0
min = min1
If min59 Then
min = 0
hour = hour1
End If
End If
Label1.Caption = ""
Label1.Caption = Format(hour, "00")":"Format(min, "00")":"Format(sec, "00")
End Sub
VB.net module中如何使用计时器?控制台调用Timer和窗体是类似vb.net线程计时器的 。首先在项目引用里面加入System.Windows.Forms程序集vb.net线程计时器 , 然后在代码顶部引入命名空间:
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 计时器的问题不对 。步骤如下vb.net线程计时器:
添加一个label标签名字label1 用来显示时间
再添加一个timer控件 名字timer1interval属性=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做毫秒计时器(有没有什么类似于ccrptmr之类的控件)不需要控件就可以,用多线程的方式实现,在窗体上放一个Label和一个button按钮,代码如下:
Imports System.Threading
Public Class Form1
Dim Start As Double
Dim td As Thread
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "00:00:00 000"
Button1.Text = "开始"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "开始" Then
Button1.Text = "结束"
Start = DateAndTime.Timer
td = New Thread(AddressOf fun1)
td.Start()
Else
Button1.Text = "开始"
td.Abort()
End If
End Sub
'定义一个线程
Private Sub fun1()
Dim elapsed As TimeSpan
Dim Dg_txt As New Dg(AddressOf txt)
Do
elapsed = TimeSpan.FromMilliseconds((DateAndTime.Timer - Start) * 1000)
Me.Invoke(Dg_txt, elapsed.ToString, Label1)
Thread.Sleep(100)
Loop
End Sub
'定义一个委托
Delegate Sub Dg(ByVal s As String, ByVal obj As Label)
Sub txt(ByVal s As String, ByVal obj As Label)
obj.Text = s
End Sub
End Class
【vb.net线程计时器的简单介绍】vb.net线程计时器的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、vb.net线程计时器的信息别忘了在本站进行查找喔 。

    推荐阅读