Visual C#

Example Application: The Progress Clock

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. Application…

1 min read316 words

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. Application: Creating the Application

  1. Start a new Windows Application named ProgressClock1
  2. Design the form as follows: Control Text Name Other Properties Label Time Anchor: Right Label Hours: ProgressBar 00 Anchor: Left, Right Label lblHours Label Minutes: ProgressBar Anchor: Left, Right Label 00 lblMinutes Anchor: Right Label Seconds: ProgressBar Anchor: Left, Right Label 00 lblSeconds Anchor: Right Button Close btnClose Anchor: Right 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:
  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
  14. Close the form and return to your programming environment

Home Copyright © 2010-2011 C#Key