LED Digital Clock
An LED digital clock is one of the classic forms of time
display. Using the LED control created earlier, you can put together a composite
control that displays time very easily.
The clock is a user control that hosts other controls,
namely, five LEDControl objects. It has few properties because it simply
displays the current time and so all you can adjust is the foreground colour and
whether the clock displays 24 or 12 hour format time.
Because the LEDControl objects display a simple character,
the control obtains the time by using the DateTime.Now property and massaging
the information that comes back. In particular, the hour is modified according
to whether 12 or 24 hour format is chosen. A couple of strings are created, one
for minutes and one for hours, and the characters in these 2 digit strings used
to populate the LEDControls that display each character. In addition the colon
flashes on and off at 1 second intervals to show that the clock is doing
something while the minutes are waiting to change. These operations are
performed in response to a 100 millisecond timer tick so that the clock is
updated at a reasonable speed.
The code that handles the timer tick
is shown here.
Figure 1 shows the LED Clock control in the design-time.

Figure 1. The LED Clock at work.
You can find the Source Code files here.
Return to the main index.