Home

Example Application:
The Progressive Clock

 

Progressive Clock

Introduction

This application simulates a clock. Each part (the hour, the minute, and the second) of the time is represented by a progress bar. As the value of the part changes, so does the progress bar. To assist the user with the current time, a label displays the corresponding value of either the hour, the minute or the second.

Windows Controls:

 

   

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  pgrHours Anchor: Left, Right
    Style: Continuous
    Maximum: 23
    Minimum: 1
    Label Label   lblHours  
    Label Label Minutes:    
    ProgressBar  ProgressBar    pgrMinutes Anchor: Left, Right
    Style: Continuous
    Maximum: 59
    Minimum: 1
    Label Label 00 lblMinutes Anchor: Right
    Label Label Seconds:    
    ProgressBar  ProgressBar    pgrSeconds Anchor: Left, Right
    Style: Continuous
    Maximum: 59
    Minimum: 1
    Label Label 00 lblSeconds Anchor: Right
    Button Button Close btnClose Anchor: Right
    Timer Timer     Enabled: True
    Interval: 20
  3. Double-click the timer control to generate its Tick event and implement it as follows:
     
    Private Sub timer1Tick(ByVal sender As System.Object, 
                                ByVal e As System.EventArgs) 
                                Handles timer1.Tick
            ' Get the current time
            Dim curTime As DateTime = DateTime.Now
            ' Retrieve the hour value of the current time
            Dim H As Integer = curTime.Hour
            ' Retrieve the minute value of the current time
            Dim M As Integer = curTime.Minute
            ' Retrieve the second value of the current time
            Dim S As Integer = 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 = CStr(H)
            lblMinutes.Text = CStr(M)
            lblSeconds.Text = CStr(S)
    End Sub
  4. In the Class Name combo box, select btnClose
  5. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnCloseClick(ByVal sender As Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles btnClose.Click
            End
    End Sub
  6. Execute the application to test it then close the form:
     
    Progressive Clock
  7. Close the form and return to your programming environment
 

Home Copyright © 2008-2012 FunctionX