Clock Control
An analogue clock face for Windows Forms – a live wall clock, a world clock for another time zone, or a fixed time shown as a picture – drawn entirely in code, so it is sharp at any size and display scale.
Assembly
| Assembly | Binarymission.WinForms.Controls.Clock.dll |
| Root namespace | Binarymission.WinForms.Controls.TimeControls |
| Target frameworks | .NET Framework 4.8, .NET 6 / 8 / 10 |
| Depends on | DoubleBufferedControlBase |
Overview
What it shows
By default the clock shows the computer's time and redraws once a second. Set
TimeZoneId to show the time in another zone, daylight saving included, or
StaticTime to stop the hands at a given time – for an appointment, a time stamp or a
"next collection" notice. Time says which time is on the face.
The hands are drawn from the time at each redraw and do not sweep: the second hand moves once per
RefreshInterval, the minute hand moves on the minute, and the hour hand moves half a degree a
minute.
The parts of the face
- The border (
ShouldDrawBorder,BorderThickness,BorderStartColor) and an optional glass shine on it (ShouldDrawGlassEffectOnBorder). - The face (
BackgroundStartColor,BackgroundEndColor) and an optional glass shine across its top (ShouldDrawGlassEffect). - The twelve hour labels (
ShouldDrawNumerals,TimeRepresentationMode) and the minute marks between them (ShouldDrawMinuteIndicatorVisual). - The hub (
ShouldDrawInnerRing) and the three hands, each a two-colour gradient with its own width. - A soft drop shadow under the whole clock (
ShouldDropShadowBeEnabled) and, optionally, under each hand (ShouldDrawDropShadowForTimeHandles).
Size and scale
Keep the control square: the face fills the client area, and the minute marks are drawn only when it is a circle. Widths and thicknesses are in logical pixels (1/96 inch) and are scaled for the display the clock is on. The control's corners are transparent, so the parent's background shows round the face.
Getting started
A world clock for the London office beside the local one, with Roman numerals and a glass face.
using System.Drawing;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.TimeControls;
var london = new Clock
{
Location = new Point(16, 16),
Size = new Size(200, 200),
TimeZoneId = "GMT Standard Time",
TimeRepresentationMode = TimeRepresentationMode.RomanNumeral,
BackgroundStartColor = Color.MidnightBlue,
BackgroundEndColor = Color.SteelBlue,
BorderThickness = 10,
ShouldDrawGlassEffect = true,
SecondHandStartColor = Color.OrangeRed,
SecondHandEndColor = Color.Gold
};
var caption = new Label { Location = new Point(16, 222), AutoSize = true, Text = "London" };
london.DoubleClick += (sender, e) => caption.Text = "London: " + london.Time.ToString("HH:mm");
form.Controls.Add(london);
form.Controls.Add(caption);API reference
Binarymission.WinForms.Controls.TimeControls
class Clock | An analogue clock face for Windows Forms - a live wall clock, a world clock for another time zone, or a fixed time shown as a picture - drawn entirely in code, so it is sharp at any size and display scale. |
enum TimeRepresentationMode | Specifies how a Clock writes the twelve hour labels round its face. |