我正在尝试创建一个非常简单的程序,基本上是一个计时器.我有三套标签lbl_seconds,lbl_minutes和lbl_hours.这些标签的默认值为,00:00我希望计时器为每个标签更改.我用谷歌搜索了这个,但我似乎无法找到任何有用的信息.
我需要三个独立的计时器吗?我还注意到计时器有自己的tick事件处理程序.我想这就是我需要更改标签的值.该怎么做?
小智 5
这是一个例子
Dim timercount As Integer = 60 'The number of seconds
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Timer1.Interval = 1000 'The number of miliseconds in a second
Timer1.Enabled = True 'Start the timer
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
Timer1.Enabled = False 'Stop the timer
timercount = 60 'Reset to 60 seconds
lblOutput.Text = timercount.ToString() 'Reset the output display to 60
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lblOutput.Text = timercount.ToString() 'show the countdown in the label
If timercount = 0 Then 'Check to see if it has reached 0, if yes then stop timer and display done
Timer1.Enabled = False
lblOutput.Text = "Done"
Else 'If timercount is higher then 0 then subtract one from it
timercount -= 1
End If
End Sub
Run Code Online (Sandbox Code Playgroud)