Home

Example Application: The Progress Clock

     

Description

This is an example of an application that uses the progress bar to display the current time. It gets the actual time from the computer.

 

ApplicationApplication: Creating the Application

  1. Start a new Windows Application named ProgressClock1
  2. Design the form as follows:
     
    Progressive Clock - Form Design
     
    Control Text Name Other Properties
    Label Label Time   Anchor: Right
    Label Label Hours:    
    ProgressBar ProgressBar 00   Anchor: Left, Right
    Label Label   lblHours  
    Label Label Minutes:    
    ProgressBar  ProgressBar     Anchor: Left, Right
    Label Label 00 lblMinutes Anchor: Right
    Label Label Seconds:    
    ProgressBar  ProgressBar     Anchor: Left, Right
    Label Label 00 lblSeconds Anchor: Right
    Button Button Close btnClose Anchor: Right
    Timer Timer     Enabled: True
    Interval: 20
  3. Change the properties of the progress bar controls as follows:
     
    Name Maximum Step
    pgrHours 23 1
    pgrMinutes 59 1
    pgrSeconds 59 1
  4. Double-click the timer control to generate its Tick event and implement it as follows:
    private void timer1_Tick(object sender, EventArgs e)
    {
                // Get the current time
                DateTime curTime = DateTime.Now;
                // Retrieve the hour value of the current time
                int H = curTime.Hour;
                // Retrieve the minute value of the current time
                int M = curTime.Minute;
                // Retrieve the second value of the current time
                int S = curTime.Second;
    
                // Draw the progress boxes based on the values of the time
                pgrHours.Value = H;
                pgrMinutes.Value = M;
                pgrSeconds.Value = S;
    
                // Display the values in the corresponding labels
                lblHours.Text = H.ToString();
                lblMinutes.Text = M.ToString();
                lblSeconds.Text = S.ToString();
    }
  5. Double-click the Close button and implement it as follows:
     
    private void btnClose_Click(object sender, EventArgs e)
    {
            Close();
    }
  6. Execute the application to test it then close the form:
     
    Progressive Clock
  7. Close the form and return to your programming environment
  8. On the form, click the top progress bar
  9. Press and hold Ctrl
  10. Click the other two progress bars
  11. Release Ctrl
  12. In the Properties window, click Style, click the arrow of its combo box, and select Continuous
  13. Execute the application to see the result
     
    Progressive Clock
  14. Close the form and return to your programming environment
 

Home Copyright © 2010-2016, FunctionX