VB.Net - Stopwatch

on Kamis, 21 Desember 2017

 

 
 

No.
Kontrol
Properties
1
Label1
Text = 00
2
Button1
Name = btnStart
Text = Start
3
Button2
Name = btnStop
Text = Stop
4
Button3
Name = btnReset
Text = Reset
5
Timer1
Enabled = true
Interval = 1













Public Class Form1
    Dim ms, s, m, h As Integer
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Stop()
        ms = 0
        s = 0
        m = 0
        h = 0
        Label1.Text = Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00") & ":" & Format(ms, "00")
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        ms = ms + 1
        If ms = 60 Then
            s = s + 1
            ms = 0
        End If
        If s = 60 Then
            m = m + 1
            s = 0
        End If
        If m = 60 Then
            h = h + 1
            m = 0
        End If
        Label1.Text = Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00") & ":" & Format(ms, "00")
    End Sub

    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
        Timer1.Start()
    End Sub

    Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
        Timer1.Stop()
    End Sub
    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        ms = 0
        s = 0
        m = 0
        h = 0
        Label1.Text = Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00") & ":" & Format(ms, "00")
    End Sub
End Class 

0 komentar: