-
Notifications
You must be signed in to change notification settings - Fork 1
/
FormDraw.cs
100 lines (81 loc) · 3.06 KB
/
FormDraw.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using System.Runtime.InteropServices;
namespace OCRGet
{
public partial class FormDraw : Form
{
//[DllImport("User32.dll")]
//public static extern IntPtr GetDC(IntPtr hwnd);
//[DllImport("User32.dll")]
//public static extern void ReleaseDC(IntPtr dc);
private Rectangle rectRegion;
private Point startPoint, endPoint;
private Boolean isDrawing = false;
public Rectangle area { get { return this.rectRegion; } set { this.rectRegion = value; } }
public FormDraw()
{
InitializeComponent();
ShowInTaskbar = false;
BackColor = Color.White;
FormBorderStyle = FormBorderStyle.None;
Bounds = Screen.PrimaryScreen.Bounds;
TopMost = true;
Opacity = .004;
}
private void FormDraw_MouseDown(object sender, MouseEventArgs e)
{
isDrawing = true;
startPoint.X = endPoint.X = e.X;
startPoint.Y = endPoint.Y = e.Y;
rectRegion.X = e.X;
rectRegion.Y = e.Y;
rectRegion.Width = 0;
rectRegion.Height = 0;
}
private void FormDraw_MouseUp(object sender, MouseEventArgs e)
{
isDrawing = false;
ControlPaint.DrawReversibleFrame(rectRegion, this.BackColor, FrameStyle.Dashed);
Hide();
}
private void FormDraw_MouseMove(object sender, MouseEventArgs e)
{
if (!isDrawing) return;
ControlPaint.DrawReversibleFrame(rectRegion, this.BackColor, FrameStyle.Dashed);
endPoint.X = e.X;
endPoint.Y = e.Y;
rectRegion.X = Math.Min(startPoint.X, endPoint.X);
rectRegion.Y = Math.Min(startPoint.Y, endPoint.Y);
rectRegion.Width = Math.Abs(endPoint.X - startPoint.X);
rectRegion.Height = Math.Abs(endPoint.Y - startPoint.Y);
ControlPaint.DrawReversibleFrame(rectRegion, this.BackColor, FrameStyle.Dashed);
//IntPtr desktopDC = GetDC(IntPtr.Zero);
//Graphics g = Graphics.FromHdc(desktopDC);
//g.DrawRectangle(System.Drawing.Pens.Red, rectDraw);
//g.Dispose();
//ReleaseDC(desktopDC);
}
private void FormDraw_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Escape)
{
if (isDrawing)
ControlPaint.DrawReversibleFrame(rectRegion, this.BackColor, FrameStyle.Dashed);
isDrawing = false;
rectRegion.Width = 0;
Hide();
}
}
private void FormDraw_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
}
}
}