Quantcast
Channel: Timer
Viewing all articles
Browse latest Browse all 4

Timer

$
0
0
Use the stopwatch elapsed method.  Here is an example you can apply to your project:

Public Class Form1
    Dim sw As New Stopwatch

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = "00:00:00"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
        sw.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = sw.Elapsed.ToString.Remove(8)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Label1.Text = "00:00:00" Then Exit Sub
        sw.Stop()
        Timer1.Stop()
        Button1.Text = "Restart"
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        sw.Stop()
        Timer1.Stop()
        sw.Reset()
        Label1.Text = "00:00:00"
        Button1.Text = "Start"
    End Sub

Solitaire

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>