My own version of Stopwatch using VB.NET

Posted on at


 

Public Class stopwatch


Dim running As Boolean = False
Dim seconds As Integer = 0, minutes As Integer = 0, hours As Integer = 0, lapCount As Integer = 0

Private Sub updateControls()
Label1.Text = hours & ":" & minutes & ":" & seconds
End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
seconds += 1
If (seconds = 60) Then
seconds = 0
minutes += 1
If (minutes = 60) Then
minutes = 0
hours += 1
End If
End If
updateControls()
End Sub

Private Sub lnkstart_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkstart.LinkClicked
running = True
Timer1.Enabled = True
Timer1.Start()

If lnkstart.Text = "RESUME" Then
lnkstart.Text = "START"
lnkstop.Enabled = True
End If
End Sub

Private Sub lnklap_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnklap.LinkClicked
lapCount += 1
lstlap.Items.Add("Lap " & lapCount & " - " & hours & ":" & minutes & ":" & seconds)
End Sub

Private Sub lnkstop_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkstop.LinkClicked
running = False
Timer1.Stop()
Timer1.Enabled = False
lnkstop.Enabled = False
lnkstart.Text = "RESUME"
End Sub


End Class



About the author

alyka

Happy Person

Subscribe 0
160