-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawer.cs
70 lines (58 loc) · 1.79 KB
/
Drawer.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
using System.Drawing;
using System.Windows.Forms;
namespace NeuralNetworkExample2
{
public class Drawer
{
public Bitmap bmp = new Bitmap(100, 100);
static Color defaultColor = Color.Black; //Default color
Point CurrentPoint; //Current Position
Point PrevPoint; //Previous Position
bool isMousePressed;
Graphics g;
Graphics g1;
Pen p = new Pen(defaultColor, 3);
Panel panelToDrawOn;
public Drawer(Panel panel)
{
this.panelToDrawOn = panel;
g = panelToDrawOn.CreateGraphics();
g1 = Graphics.FromImage(bmp);
panelToDrawOn.MouseMove += panel_MouseMove;
panelToDrawOn.MouseDown += panel_MouseDown;
panelToDrawOn.MouseUp += panel_MouseUp;
panelToDrawOn.Paint += panel_Paint;
}
public void Clear(Color backcolor)
{
g.Clear(panelToDrawOn.BackColor);
g1.Clear(panelToDrawOn.BackColor);
}
#region draw events
void panel_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Save();
}
void panel_MouseUp(object sender, MouseEventArgs e)
{
isMousePressed = false;
}
void panel_MouseDown(object sender, MouseEventArgs e)
{
isMousePressed = true;
CurrentPoint = e.Location;
}
void panel_MouseMove(object sender, MouseEventArgs e)
{
if (!isMousePressed)
{
return;
}
PrevPoint = CurrentPoint;
CurrentPoint = e.Location;
g.DrawEllipse(p, PrevPoint.X, PrevPoint.Y, 3, 3);
g1.DrawEllipse(p, PrevPoint.X, PrevPoint.Y, 3, 3);
}
#endregion
}
}