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/ScreenSaver.cs

49 lines
832 B
C#

using App;
using System;
using System.Drawing;
using System.Windows.Forms;
using Timer = System.Windows.Forms.Timer;
class ScreenSaver
{
private readonly Timer timer = new();
public ScreenSaver()
{
timer.Interval = 1000;
timer.Tick += OnTick;
}
public void Run()
{
// Create windows for all screens.
foreach (Screen s in Screen.AllScreens) {
if (s.Primary) {
_ = new MainWindow(s.Bounds);
} else {
_ = new Window(s.Bounds);
}
}
timer.Start();
OnTick(null, null);
Application.Run();
}
private void OnTick(object? myObject, EventArgs? myEventArgs)
{
Update();
}
private static void Update()
{
// Update background color for all forms.
Color color = ColorUtil.TimeToColor(DateTime.Now);
foreach (Form form in Application.OpenForms) {
form.BackColor = color;
}
}
}