HypernovaDesktop Components · docs
Binarymission
WinForms › Clock Control

Clock Control

.NET Framework 4.8.NET 6 / 8 / 10v3.1.0WinForms

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.

2public types
52public members
1namespaces

Assembly

AssemblyBinarymission.WinForms.Controls.Clock.dll
Root namespaceBinarymission.WinForms.Controls.TimeControls
Target frameworks.NET Framework 4.8, .NET 6 / 8 / 10
Depends onDoubleBufferedControlBase

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

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 ClockAn 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 TimeRepresentationModeSpecifies how a Clock writes the twelve hour labels round its face.