using System; using System.Drawing; using System.Windows.Forms; namespace App { class Window : Form { private Point mousePos; public Window() { InitializeComponent(new Rectangle(0, 0, 200, 200)); } public Window(Rectangle bounds) { InitializeComponent(bounds); } public Window(Screen scr) { InitializeComponent(scr.Bounds); } private void InitializeComponent(Rectangle bounds) { Bounds = bounds; // Set some good values for a Sreensaver window. BackColor = Color.White; FormBorderStyle = FormBorderStyle.None; StartPosition = FormStartPosition.Manual; Cursor.Hide(); ShowInTaskbar = false; TopMost = true; DoubleBuffered = true; // Register events MouseMove += OnMouseMove; KeyPress += OnKeyPressed; Show(); } private void OnMouseMove(object? sender, MouseEventArgs e) { if (!mousePos.IsEmpty && (Math.Abs(e.Location.X - mousePos.X) > 1 || Math.Abs(e.Location.Y - mousePos.Y) > 1)) { Application.Exit(); } mousePos = e.Location; } private void OnKeyPressed(object? sender, KeyPressEventArgs e) { Application.Exit(); } } }