using System; using System.Windows.Forms; using Timer = System.Windows.Forms.Timer; /* * ClockLabel is a special label that will display the system time. */ class ClockLabel : Label { /** * Timer to update the time. */ private readonly Timer timer = new(); /** * Textformat to use. */ public string Format { get; set; } public ClockLabel(string format = "HH:mm:ss") { Format = format; Initialize(); } protected void Initialize() { timer.Interval = 1000; timer.Tick += Timer_Tick; Timer_Tick(null, null); timer.Start(); } private void Timer_Tick(object? sender, EventArgs? e) { Text = DateTime.Now.ToString(Format); } }