我试图添加一个正常运行时间计数器,以便从我的应用程序启动开始,它就启动一个计时器,该计时器以秒为单位递增,直到应用程序关闭或故意停止它为止。
当前,计时器先计数第一秒,然后停止。这可能是我不了解滴答功能吗?我假设我为计时器设置的时间间隔将刷新或循环在tick子程序中的代码吗?(我可以大错特错)。
我有timer1,并将其设置为"Enabled"
,并将间隔设置"1000"
为1秒钟。
在我的Timer1_Tick Sub
我有这个:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim seconds, minutes, hours As Integer
If seconds = 60 Then
seconds = 0
minutes = minutes + 1
End If
If minutes = 60 Then
If seconds = 60 Then
seconds = 0
minutes = 0
hours = hours + 1
End If
End If
seconds = seconds + 1
Label44.Text = Format(hours, "00") & "." & Format(minutes, "00") & "." & Format(seconds, "00")
End Sub
在Form1_Load
我有Timer1.Start()
请您告诉我我想念的是什么吗?谢谢。
您需要在中声明变量Form1
。
Public Class Form1
Private seconds, minutes, hours As Integer
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
If seconds = 60 Then
seconds = 0
minutes = minutes + 1
End If
If minutes = 60 Then
If seconds = 60 Then
seconds = 0
minutes = 0
hours = hours + 1
End If
End If
seconds = seconds + 1
Label44.Text = Format(hours, "00") & "." & Format(minutes, "00") & "." & Format(seconds, "00")
End Sub
End Class
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句