-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathButton_WOC1.cs
136 lines (116 loc) · 3.74 KB
/
Button_WOC1.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ePOSOne.btnProduct
{
public class Button_WOC1 : Button
{
private Color _borderColor = Color.Silver;
private Color _onHoverBorderColor = Color.Gray;
private Color _buttonColor = Color.Red;
private Color _onHoverButtonColor = Color.Yellow;
private Color _textColor = Color.White;
private Color _onHoverTextColor = Color.Gray;
private bool _isHovering;
private int _borderThickness = 6;
private int _borderThicknessByTwo = 3;
public Button_WOC1()
{
DoubleBuffered = true;
MouseEnter += (sender, e) =>
{
_isHovering = true;
Invalidate();
};
MouseLeave += (sender, e) =>
{
_isHovering = false;
Invalidate();
};
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Brush brush = new SolidBrush(_isHovering ? _onHoverBorderColor : _borderColor);
//Border
g.FillEllipse(brush, 0, 0, Height, Height);
g.FillEllipse(brush, Width - Height, 0, Height, Height);
g.FillRectangle(brush, Height / 2, 0, Width - Height, Height);
brush.Dispose();
brush = new SolidBrush(_isHovering ? _onHoverButtonColor : _buttonColor);
//Inner part. Button itself
g.FillEllipse(brush, _borderThicknessByTwo, _borderThicknessByTwo, Height - _borderThickness,
Height - _borderThickness);
g.FillEllipse(brush, (Width - Height) + _borderThicknessByTwo, _borderThicknessByTwo,
Height - _borderThickness, Height - _borderThickness);
g.FillRectangle(brush, Height / 2 + _borderThicknessByTwo, _borderThicknessByTwo,
Width - Height - _borderThickness, Height - _borderThickness);
brush.Dispose();
brush = new SolidBrush(_isHovering ? _onHoverTextColor : _textColor);
//Button Text
SizeF stringSize = g.MeasureString(Text, Font);
g.DrawString(Text, Font, brush, (Width - stringSize.Width) / 2, (Height - stringSize.Height) / 2);
}
public Color BorderColor
{
get => _borderColor;
set
{
_borderColor = value;
Invalidate();
}
}
public Color OnHoverBorderColor
{
get => _onHoverBorderColor;
set
{
_onHoverBorderColor = value;
Invalidate();
}
}
public Color ButtonColor
{
get => _buttonColor;
set
{
_buttonColor = value;
Invalidate();
}
}
public Color OnHoverButtonColor
{
get => _onHoverButtonColor;
set
{
_onHoverButtonColor = value;
Invalidate();
}
}
public Color TextColor
{
get => _textColor;
set
{
_textColor = value;
Invalidate();
}
}
public Color OnHoverTextColor
{
get => _onHoverTextColor;
set
{
_onHoverTextColor = value;
Invalidate();
}
}
private void InitializeComponent()
{
this.SuspendLayout();
this.ResumeLayout(false);
}
}
}