Progressive Clock

Introduction

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++ Projects .NET as a Windows Forms Application. Name it ProgressClock
  2. Change the Form properties as follows:
    FormBorderStyle: FixedDialog
    MaximizeBox: False
    MaximizeBox: False
    Text: Progressive Clock
  3. Add three Label controls to the left section of the dialog box with Text from top down as Hours:, Minutes:, and Seconds: respectively
    You will design the dialog box as follows:
     
  4. From the Toolbox, click ProgressBar and click on the right side of the Hours label
  5. Change its properties as follows:
    Name to pgrHours
    Maximum: 23
    Step: 1
  6. From the Toolbox, click ProgressBar and click on the right side of the Minutes label
    Change its properties as follows:
    Name to pgrMinutes
    Maximum: 59
    Step: 1
  7. From the Toolbox, click ProgressBar and click on the right side of the Seconds label
    Change its properties as follows:
    Name to pgrSeconds
    Maximum: 59
    Step: 1
  8. Add a Label control to the right side of the Hours progress bar. Change its properties as follows:
    Name: lblHours
    Text: 00
    TextAlign: MiddleCenter
  9. Add a Label control to the right side of the Minutes progress bar. Change its properties as follows:
    Name: lblMinutes
    Text: 00
    TextAlign: MiddleCenter
  10. Add a Label control to the right side of the Minutes progress bar. Change its properties as follows:
    Name: lblSeconds
    Text: 00
    TextAlign: MiddleCenter
  11. From the Toolbox, add a Timer control to the form
  12. Double-click the Time to generate its Tick() event and implement it as follows:
     
    private: System::Void timer1_Tick_1(System::Object *  sender, System::EventArgs *  e)
    		 {
    			 DateTime curTime = DateTime::Now;
    			 int H = curTime.Hour;
    			 int M = curTime.Minute;
    			 int S = curTime.Second;
    
    			 pgrHours->Value = H;
    			 pgrMinutes->Value = M;
    			 pgrSeconds->Value = S;
    
    			 lblHours->Text = H.ToString();
    			 lblMinutes->Text = M.ToString();
    			 lblSeconds->Text = S.ToString();
    		 }
  13. Test the application
  14. After using it, close it and return to your programming environment.

 

 

Home Copyright © 2003 FunctionX, Inc. FunctionX