yogi_bear_79
Member
- Joined
- Sep 30, 2009
- Messages
- 19
- Programming Experience
- Beginner
My timer pauses (sort of) the display portion (label) of the timer indeed pauses, however when the timer is resumed it starts again, but not at the point where it was disabled. As an example. If I pause the timer at 10:00 and wait ten seconds when I hit resume it starts at 09:50, where it should resume at 10:00 or 09:59
VB.NET:
Module Helper
Public SessionTime As String
Public Pause As Boolean = False
End Module
Public Class frmMain
Public SessionTimer As Date
Private Sub btnSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Me.SessionTimer = Date.Now.AddMinutes(Val(SessionTime))
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim remainingTime As TimeSpan = Me.SessionTimer.Subtract(Date.Now)
Me.lblTime.Text = String.Format("{0}:{1:d2}:{2:d2}", _
remainingTime.Hours, _
remainingTime.Minutes, _
remainingTime.Seconds)
End Sub
Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
If Pause = False Then
'...Button was labled "Pause" => Pause
btnPause.Text = "Resume"
Else
'...Button was labled "Resume" => Resume
btnPause.Text = "Pause"
End If
Timer1.Enabled = Pause '...Pause/Resume timer based on boolean state
Pause = Not (Pause) '...Invert Boolean
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
Me.Timer1.Stop()
End Sub
End Class