1
0
Fork 0
This repository has been archived on 2026-06-16. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
colorclock-screensaver/ClockLabel.cs

41 lines
667 B
C#

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);
}
}