-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKeyButton.cs
91 lines (80 loc) · 3.17 KB
/
KeyButton.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace IPA
{
public class KeyButton : Control
{
GraphicsPath border;
int penWidth = 1;
int c = 5;
public KeyButton()
{
base.Font = Properties.Settings.Default.buttonFont;
}
protected override System.Drawing.Size DefaultSize
{
get
{
return new System.Drawing.Size(Properties.Settings.Default.buttonWidth, Properties.Settings.Default.buttonHeight);
}
}
protected override void OnCreateControl()
{
base.OnCreateControl();
Rectangle borderRect = new Rectangle(penWidth / 2, penWidth / 2, Width - penWidth, Height - penWidth);
border = new GraphicsPath();
Point p1 = new Point(borderRect.X, borderRect.Y + c);
Point p2 = new Point(borderRect.X + c, borderRect.Y);
Point p3 = new Point(borderRect.Right - c, borderRect.Y);
Point p4 = new Point(borderRect.Right, borderRect.Y + c);
Point p5 = new Point(borderRect.Right, borderRect.Bottom - c);
Point p6 = new Point(borderRect.Right - c, borderRect.Bottom);
Point p7 = new Point(borderRect.X + c, borderRect.Bottom);
Point p8 = new Point(borderRect.X, borderRect.Bottom - c);
border.AddArc(p1.X, p2.Y, 2 * c, 2 * c, 180, 90);
border.AddLine(p2, p3);
border.AddArc(p3.X - c, p4.Y - c, 2 * c, 2 * c, -90, 90);
border.AddLine(p4, p5);
border.AddArc(p5.X - 2*c, p6.Y - 2*c, 2 * c, 2 * c, 0, 90);
border.AddLine(p6, p7);
border.AddArc(p7.X -c, p8.Y - c, 2 * c, 2 * c, 90, 90);
border.AddLine(p8, p1);
}
bool mouseEntered = false;
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
mouseEntered = true;
Invalidate();
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
mouseEntered = false;
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
using (Pen p = new Pen(Properties.Settings.Default.buttonBorderColor))
{
p.Width = penWidth;
e.Graphics.DrawPath(p, border);
}
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
if(mouseEntered)
e.Graphics.DrawString(Text,Font, Brushes.Gray,ClientRectangle ,sf);
else
e.Graphics.DrawString(Text, Font, Brushes.Black, ClientRectangle, sf);
}
}
}