I would like to know how I can pause a stopwatch, and resume the timer by clicking the start button. Also I would like to display the start date, start time and application active time in the text boxes on the VB form.
Any help would be appreciated.
Here is my code:
Option Explicit On
Option Strict On
Public Class Form1
Private StartTime, EndTime As Date
Private Sub TextBox12_TextChanged(ByVa
l sender As System.Object, ByVal e As System.EventArgs) Handles txtHourActive.TextChanged
End Sub
Private Sub TextBox10_TextChanged(ByVa
l sender As System.Object, ByVal e As System.EventArgs) Handles lblSpanHours.TextChanged
End Sub
Private Sub TextBox11_TextChanged(ByVa
l sender As System.Object, ByVal e As System.EventArgs) Handles txtHourPaused.TextChanged
End Sub
Private Sub TextBox7_TextChanged(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles lblSpanMinutes.TextChanged
End Sub
Private Sub TextBox8_TextChanged(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles txtMinPaused.TextChanged
End Sub
Private Sub TextBox9_TextChanged(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles txtMinActive.TextChanged
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
Dim CurrentSpan As TimeSpan
EndTime = Now
' Calcualte the time span.
CurrentSpan = EndTime - StartTime
' Display the current property values.
lblSpanMilliseconds.Text = CurrentSpan.Milliseconds.T
oString
lblSpanSeconds.Text = CurrentSpan.Seconds.ToStri
ng
lblSpanMinutes.text = CurrentSpan.Minutes.ToStri
ng
lblSpanHours.Text = CurrentSpan.Hours.ToString
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
lblSpanMilliseconds.Text = "0"
lblSpanSeconds.Text = "0"
lblSpanMinutes.Text = "0"
lblSpanHours.Text = "0"
End Sub
Private Sub txtStartDate_TextChanged(B
yVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStartDate.TextChanged
End Sub
Private Sub lblCurrentTime_TextChanged
(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblCurrentTime.TextChanged
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Timer.Enabled = True
StartTime = Now
End Sub
Private Sub txtMilElapsed_TextChanged(
ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblSpanMilliseconds.TextCh
anged
End Sub
Private Sub activeTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub lblActiveTime_TextChanged(
ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblActiveTime.TextChanged
End Sub
Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
End Sub
Private Sub tmrCurrent_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrCurrent.Tick
lblCurrentTime.Text = String.Format("{0:hh:mm:ss
tt}", Date.Now)
End Sub
End Class
Start Free Trial