In this post we teach you about stopwatch. That's how we create a stopwatch in VB.NET. This is a very easy task. For this we have to take four number labels from the toolbox. And after that two number buttons have to be pressed. After that is to use the below coding as per video instruction.
Public Class Form1
Dim msecond As Integer
Dim seconds As Integer
Dim minutes As Integer
Dim hours As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()
Timer1.Interval = 100
msecond = 0
seconds = 0
minutes = 0
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If msecond = 10 Then
seconds = seconds + 1
msecond = 0
End If
If seconds = 60 Then
minutes = minutes + 1
seconds = 0
End If
If minutes = 60 Then
hours = hours + 1
minutes = 0
End If
Label1.Text = hours.ToString("00")
Label2.Text = minutes.ToString("00")
Label3.Text = seconds.ToString("00")
Label4.Text = msecond.ToString("00")
msecond = msecond + 1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Stop()
End Sub
End Class