【发布时间】:2015-01-26 03:28:51
【问题描述】:
请任何人帮助我解决我的计时器问题。我将计时器设置为 1 分钟。 (60 秒)。通过单击开始和暂停按钮运行良好,但是在单击另一个按钮以恢复时间后,它在我暂停的时间上并不准确。 示例:我启动计时器(1 分钟)并暂停到 40 秒。恢复后,时间不完全是我的时间暂停。不是 40 秒,而是 30 秒开始,这取决于我什么时候点击恢复按钮。即使我停止计时器,它也会继续运行。这是我的代码。
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If alarmTime < Date.Now Then
' Display the new time left
' by updating the Time Left label.
Timer2.Stop()
MessageBox.Show("Times Up!.", "Thank you!")
BtnBack.Enabled = True
startButton.Enabled = False
BtnSubmit.Enabled = False
AnsA.Enabled = False
AnsB.Enabled = False
AnsC.Enabled = False
AnsD.Enabled = False
BtnNext.Enabled = False
BtnPrev.Enabled = False
BtnClose.Enabled = True
Categoriess.lnkMathHS.Enabled = False
Else
Dim remainingtime As TimeSpan '= Me.alarmTime.Subtract(Date.Now)
remainingtime = Me.alarmTime.Subtract(Date.Now)
timeLabel.Text = String.Format("{0}:{1:d2}:{2:d2}", _
remainingtime.Hours, _
remainingtime.Minutes, _
remainingtime.Seconds)
End If
End Sub
Private Sub startButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startButton.Click
alarmTime = Date.Now.AddMinutes(TextBox1.Text)
Timer2.Start()
End Sub
Private Sub resumeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resumeButton.Click
Timer2.start()
End Sub
Private Sub stopButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stopButton.Click
Timer2.stop()
End Sub
【问题讨论】:
标签: vb.net timer countdowntimer