This repository was archived by the owner on Nov 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFrmScreenSelectionOverlay.cs
More file actions
102 lines (94 loc) · 2.5 KB
/
Copy pathFrmScreenSelectionOverlay.cs
File metadata and controls
102 lines (94 loc) · 2.5 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
namespace UmatoMusume
{
public class FrmScreenSelectionOverlay : Form
{
public Rectangle SelectedRectangle { get; private set; }
private Point _startPoint;
private Point _endPoint;
private bool _dragging = false;
private Rectangle _overlayBounds;
public FrmScreenSelectionOverlay() : this(SystemInformation.VirtualScreen) { }
public FrmScreenSelectionOverlay(Rectangle _bounds)
{
_overlayBounds = _bounds;
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = false;
TopMost = true;
BackColor = Color.White;
Opacity = 0.2;
DoubleBuffered = true;
Cursor = Cursors.Cross;
Bounds = _overlayBounds;
StartPosition = FormStartPosition.Manual;
KeyPreview = true;
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
Close();
}
base.OnKeyDown(e);
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_dragging = true;
_startPoint = new Point(e.X + _overlayBounds.Left, e.Y + _overlayBounds.Top);
_endPoint = _startPoint;
Invalidate();
}
base.OnMouseDown(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (_dragging)
{
_endPoint = new Point(e.X + _overlayBounds.Left, e.Y + _overlayBounds.Top);
Invalidate();
}
base.OnMouseMove(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (_dragging && e.Button == MouseButtons.Left)
{
_dragging = false;
_endPoint = new Point(e.X + _overlayBounds.Left, e.Y + _overlayBounds.Top);
SelectedRectangle = GetRectangle(_startPoint, _endPoint);
DialogResult = DialogResult.OK;
Close();
}
base.OnMouseUp(e);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (_dragging)
{
Rectangle rect = GetRectangle(
new Point(_startPoint.X - _overlayBounds.Left, _startPoint.Y - _overlayBounds.Top),
new Point(_endPoint.X - _overlayBounds.Left, _endPoint.Y - _overlayBounds.Top)
);
using (Pen pen = new Pen(Color.Red, 2))
{
e.Graphics.DrawRectangle(pen, rect);
}
using (Brush brush = new SolidBrush(Color.FromArgb(50, Color.Blue)))
{
e.Graphics.FillRectangle(brush, rect);
}
}
}
private Rectangle GetRectangle(Point _p1, Point _p2)
{
int x = Math.Min(_p1.X, _p2.X);
int y = Math.Min(_p1.Y, _p2.Y);
int w = Math.Abs(_p1.X - _p2.X);
int h = Math.Abs(_p1.Y - _p2.Y);
return new Rectangle(x, y, w, h);
}
}
}