Create a simple timer to count seconds, minutes and hours

后端 未结 4 916
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-07 15:47

I\'m trying to create a pretty simple program that basically is a timer. I have three sets of labels, lbl_seconds, lbl_minutes and lbl_hours

4条回答
  •  终归单人心
    2021-01-07 16:16

    Start off by adding a timer. Call it whatever you like, in this example I will be keeping it as Timer1. Add a label and set the text as: 00:00.

    In the code after the class has been set (usually it is Public Class Form1) make a variable as a stopwatch: Dim stopwatch As New Stopwatch

    In the timer tick event code, put the following: (Please note that my 00:00 label is called Label1)

    Label1.Text = String.Format("{0}:{1}:{2}", watch.Elapsed.Hours.ToString("00"), watch.Elapsed.Minutes.ToString("00"), watch.Elapsed.Seconds.ToString("00"))
    

提交回复
热议问题