Home

Control-Based Application:
The Progress Clock

 

Description

This application is used to explore the characteristics of a progress bar. The application displays the current time of the computer using three progress bars: one for the hour, one for the minutes, and one for the seconds. Each progress bar uses the corresponding value of the system clock to display its progression. To assist you with knowing the exact value of each part, the application is equipped with three labels on the right side of the progress bars.

Practical LearningPractical Learning: 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. Save all
  4. Change the properties of the progress bar controls as follows:
     
    Name Maximum Step
    pgrHours 23 1
    pgrMinutes 59 1
    pgrSeconds 59 1
  5. 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();
    }
  6. Double-click the Close button and implement it as follows:
     
    private void btnClose_Click(object sender, EventArgs e)
    {
            Close();
    }
  7. Execute the application to test it then close the form:
     
    Progressive Clock
  8. Close the form and return to your programming environment
  9. On the form, click the top progress bar
  10. Press and hold Ctrl
  11. Click the other two progress bars
  12. Release Ctrl
  13. In the Properties window, click Style, click the arrow of its combo box, and select Continuous
  14. Execute the application to see the result
     
    Progressive Clock
  15. Close the form and return to your programming environment
 
 

Home Copyright 2008-2009, yevol.com