screensaver/ScreenForm.cs

100 lines
3.0 KiB
C#

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace ScreenSaver
{
public class ScreenForm : Form
{
protected Timer timer = null;
protected Point startMousePos;
protected int screenNo;
public ScreenForm(int num)
{
this.AutoScaleBaseSize = new Size(1, 1);
this.BackColor = Color.Black;
this.BackgroundImageLayout = ImageLayout.Zoom;
//this.Bounds = Screen.AllScreens[screenNo].Bounds;
this.ClientSize = new Size(320, 240);
this.FormBorderStyle = FormBorderStyle.None;
this.Name = "ScreenSaverForm";
this.StartPosition = FormStartPosition.Manual;
this.Text = "Screen " + screenNo.ToString();
this.TopMost = true;
//this.WindowState = FormWindowState.Maximized;
timer = new Timer();
timer.Interval = 4000;
timer.Tick += timer_Tick;
timer.Enabled = true;
this.screenNo = num;
}
//protected override void OnPaint(PaintEventArgs e)
//{
// base.OnPaint(e);
// e.Graphics.DrawString(screenNo.ToString() + " " + this.Bounds.ToString(), this.Font, new SolidBrush(Color.White), new PointF(100, 100));
//}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.Bounds = Screen.AllScreens[screenNo].Bounds;
Cursor.Hide();
this.TopMost = true;
}
protected override void OnKeyDown(KeyEventArgs e) => this.Close();
protected override void OnKeyPress(KeyPressEventArgs e) => this.Close();
protected override void OnKeyUp(KeyEventArgs e) => this.Close();
protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e) => this.Close();
protected override void OnClosing(CancelEventArgs e) => Application.Exit();
protected override void OnMouseMove(MouseEventArgs e)
{
//base.OnMouseMove(e);
if (!startMousePos.IsEmpty)
{
if (startMousePos != new Point(e.X, e.Y))
{
this.Close();
}
if (e.Clicks > 0)
{
this.Close();
}
}
this.startMousePos = new Point(e.X, e.Y);
}
protected override void OnMouseDoubleClick(MouseEventArgs e) => this.OnMouseMove(e);
protected override void OnMouseClick(MouseEventArgs e) => this.OnMouseMove(e);
protected override void OnMouseDown(MouseEventArgs e) => this.OnMouseMove(e);
protected override void OnMouseUp(MouseEventArgs e) => this.OnMouseMove(e);
protected override void OnMouseWheel(MouseEventArgs e) => this.OnMouseMove(e);
private void timer_Tick(object sender, EventArgs e)
{
//throw new NotImplementedException();
}
}
}