Sunday, 18 December 2016

ProgressBar Clock in VB.NET


Today, I will teach you how to create a program that displays a clock using the ProgressBar in VB.NET.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Next, add a Timer named Timer1. Insert 3 ProgressBar named ProgressBar1,ProgressBar2, and ProgressBar3 for Hour, Minute, and Seconds, respectively. Insert also labels such as lblTime for the real time, lblHour for the hour, lblMinutefor minutes, and lblSec for seconds., You must design your interface like this:
3. Now lets code for our Form.
We will have first to code the Timer1 as it ticks and will breakdown the time into hours, minutes, and seconds to display the time value of the progressbars and labels.
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
       'progressbars and labels
        ProgressBar1.Value = Convert.ToString(DateTime.Now.Hour)    'Hour
        lblHour.Text = Convert.ToString(DateTime.Now.Hour)
        ProgressBar2.Value = Convert.ToString(DateTime.Now.Minute)  'Minute
        lblMinute.Text = Convert.ToString(DateTime.Now.Minute)
        ProgressBar3.Value = Convert.ToString(DateTime.Now.Second)  'Seconds
        lblSec.Text = Convert.ToString(DateTime.Now.Second)
    End Sub
Now, we will code for the Form_Load so that it will display the exact calibration of the time such as hours, minutes, and seconds. Also, it will display the real time on our label

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'hour
        Label6.Text = "     1                 5                    10                   15                    20          23"
        Label5.Text = "|    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |"
        'minute
        Label7.Text = "| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |"
        'seconds
        Label9.Text = "| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |"

        'date
        lblTime.Text = DateTime.Today.ToLongDateString()

    End Sub

Output:




0 comments:

Post a Comment