Dim hour, min, sec As Integer
成都创新互联2013年至今,是专业互联网技术服务公司,拥有项目网站设计制作、成都网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元天台做网站,已为上家服务,为天台各地企业和个人服务,联系电话:13518219792
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
控制台调用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
不对。步骤如下:
添加一个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
用Timer控件吧,设置1秒执行1次。然后直接在Timer中写代码,将全全局的值来
减减1,如果值为0,则停止Timer
跳出提示框
以下示例:
int
Tatal
=
100;
Timer.Inveral
=
1000;
Timer_()
{
if
(
Tatal
==
0)
{
MessageBox.Show("完成!");
Timer.Stop();
}
else
{
Tatal
--;
}
}