-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathScreensaverForm.cs
More file actions
69 lines (61 loc) · 2.07 KB
/
ScreensaverForm.cs
File metadata and controls
69 lines (61 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WebScreenSaver
{
public partial class ScreensaverForm
{
// Store the number of displays
private readonly int _thisDisplayIdId;
private readonly WebpageView _view;
// Store the mouse coordinates
private Point _mouseCoords;
internal ScreensaverForm(int thisDisplayId, WebpageView view)
{
InitializeComponent();
// Assign the number to an accessible variable
_thisDisplayIdId = thisDisplayId;
_view = view;
LostFocus += (o, e) => Close();
}
public bool CloseWhenMouseMove { get; set; }
private void OnFormLoad(object sender, EventArgs e)
{
// Set the bounds of the form, fill all the screen
Bounds = Screen.AllScreens[_thisDisplayIdId].Bounds;
SuspendLayout();
Controls.Add(_view);
_view.Left = 0;
_view.Top = 0;
_view.Width = Width;
_view.Height = Height;
_view.PreviewKeyDown += OnWebBrowserPreviewKeyDown;
_view.MouseMove += OnViewMouseMove;
_view.Visible = true;
ResumeLayout();
TopMost = true;
Cursor.Hide();
}
private void OnViewMouseMove(object sender, MouseEventArgs e)
{
if (!CloseWhenMouseMove)
return;
// If mouseCoords is empty don't close the screen saver
if (!_mouseCoords.IsEmpty)
{
// If the mouse actually moved more than 10 pixes in any direction
if (Math.Abs(_mouseCoords.X - e.X) > 10
|| Math.Abs(_mouseCoords.Y - e.Y) > 10)
{
Close();
}
}
// Set the new point where the mouse is
_mouseCoords = new Point(e.X, e.Y);
}
private void OnWebBrowserPreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
Close();
}
}
}