The Digital Clock Control is a versatile user control with options for:
- Digital clock
- Stop watch
- Count down timer
- Setting multiple alarms
- Freezing the clock
- Multiple color display
- Resizable display
The digits can be displayed in three different colors - Red, Blue and Green.
The control adjusts the digits size with the size of the rectangle of the control. A ratio of 1:2 is maintained between the height and the width of the large digits and half the size for smaller ones. The clock control also supports 2 types of formats - 12 hour and 24 hour.
Using the Digital Clock control
Place the SriClocks.dll and Digital.bmp files in a single directory. At design time, right click in the ToolBox of Visual Studio, browse for and select SriClocks.dll file. The following image shows the control selected:
On pressing OK, the control is added to the ToolBox as shown below:
Now, drag and drop the control on to a form to create the Digital Clock control as any other user control.
Demo project - TestClock.exe
The demo project included shows all the capabilities and usage of the Clock control. Here is a screenshot.
Code to use the DigitalClockCtrl
To display a normal watch, which is also the default, just set the clock type to
DigitalClock as shown below. Optionally, you may set the 24 hour or 12 hour format using
DigitalClockCtrl. The 12 hour format will display 'A' for AM and 'P' for PM. The default is the 12 hour format.
digitalClockCtrl.SetClockType = SriClocks.ClockType.DigitalClock;
digitalClockCtrl.ClockDisplayFormat = SriClocks.ClockFormat.TwelveHourFormat;
To use the countdown timer, create and add delegates to the clock control's
CountDownDone event. Then set the clock type to
CountDown. When the countdown is over, the clock control will fire the
private void OnCountDownDone()
digitalClockCtrl.CountDownDone += new DigitalClockCtrl.CountDown(OnCountDownDone);
digitalClockCtrl.CountDownTime = ms;
digitalClockCtrl.SetClockType = SriClocks.ClockType.CountDown;
To start the stop watch, set the clock type to
digitalClockCtrl.SetClockType = SriClocks.ClockType.StopWatch;
To freeze the clock display, set the clock type to
ClockType.Freeze. This will freeze the clock till the clock type is reset to
StopWatch. The functionality is particularly useful when using the stopwatch.
digitalClockCtrl.SetClockType = SriClocks.ClockType.Freeze;
To change the display color, set the
SetDigitalColor property of the control to one of the
digitalClockCtrl1.SetDigitalColor = SriClocks.DigitalColor.GreenColor;
To set alarms, create delegates and add them to
RaiseAlarm event of the clock control. When an alarm is raised by the control, it fires the
public void OnRaiseAlarm()
digitalClockCtrl.RaiseAlarm += new DigitalClockCtrl.Alarm(OnRaiseAlarm);
digitalClockCtrl.AlarmTime = DateTime.Parse(Alarmtime.Text);