Practical Learning Logo

Progressive Clock



The dialog box on this exercise displays three progress bars: one holds the value of the current hour, another holds the value of the minutes in the current hour, the last displays the seconds of the current minute. We also use a label on the right side of each progress bar to display its corresponding value.

Creating the Controls

To start this application, you can use a form. Then add the necessary controls to it as we will design shortly. Although the hour holds 24 values while the minutes and the seconds hold 60 values each, we will use the same dimensions (especially the same width) for all progress controls. Because a progress control has no mechanism or message to trigger the change of its position, we will use a timer to handle such a message.

Practical Learning: Starting the Exercise

  1. Start a new Visual C# project as a Windows Forms Application
  2. Name it ProgressClock
  3. Change the Form properties as follows:
    FormBorderStyle: FixedDialog
    MaximizeBox: False
    MaximizeBox: False
    Text: Progressive Clock
  4. Design the form as follows:
    Control Name Text Other Properties
    Label Time  
    Label   Hour:  
    ProgressBar  pgrHours   Maximum: 23
    Step: 1
    Label lblHours 00  
    Label   Minute:  
    ProgressBar  pgrMinutes   Maximum: 59
    Step: 1
    Label lblMinutes 00  
    Label   Second:  
    ProgressBar  pgrSeconds   Maximum: 59
    Step: 1
    Label lblSeconds 00  
    Button btnClose Close  
    Timer     Enabled: True
    Interval: 20
  5. Double-click the Time to generate its Tick() event and implement it as follows:
    Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer1.Tick
            Dim curTime As System.DateTime = System.DateTime.Now
            Dim H As Integer = curTime.Hour
            Dim M As Integer = curTime.Minute
            Dim S As Integer = curTime.Second
            pgrHours.Value = H
            pgrMinutes.Value = M
            pgrSeconds.Value = S
            lblHours.Text = CStr(H)
            lblMinutes.Text = CStr(M)
            lblSeconds.Text = CStr(S)
        End Sub
  6. On the form, double-click the Close button and implement it as follows:
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        End Sub
  7. Test the application
  8. After using it, close it and return to your programming environment.

Home Copyright 2004-2015 FunctionX, Inc.