重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
不对。步骤如下:
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比随县网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式随县网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖随县地区。费用合理售后完善,十多年实体公司更值得信赖。
添加一个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
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
不需要控件就可以,用多线程的方式实现,在窗体上放一个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