-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomPanels.cs
More file actions
146 lines (136 loc) · 4.78 KB
/
customPanels.cs
File metadata and controls
146 lines (136 loc) · 4.78 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
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
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PcComponentsMonitor
{
public class customPanels : Panel
{
private int borderSize = 0;
private int borderRadius = 0;
private System.Data.OleDb.OleDbCommand oleDbCommand1;
private Color borderColor = Color.PaleVioletRed;
[Category("Colors")]
public int BorderSize
{
get => borderSize; set
{
borderSize = value;
this.Invalidate();
}
}
[Category("Colors")]
public int BorderRadius
{
get => borderRadius; set
{
borderRadius = value;
this.Invalidate();
}
}
[Category("Colors")]
public Color BorderColor
{
get => borderColor; set
{
borderColor = value;
this.Invalidate();
}
}
[Category("Colors")]
public Color BackgroundColor
{
get { return this.BackColor; }
set { this.BackColor = value; }
}
[Category("Colors")]
public Color TextdColor
{
get { return this.ForeColor; }
set { this.ForeColor = value; }
}
public customPanels()
{
this.Size = new Size(150, 40);
this.BackColor = Color.MediumSlateBlue;
this.ForeColor = Color.White;
}
private GraphicsPath GetFigurePath(RectangleF rect, float radius)
{
GraphicsPath path = new GraphicsPath();
float curveSize = radius * 2F;
path.StartFigure();
path.AddArc(rect.X, rect.Y, curveSize, curveSize, 180, 90);
path.AddArc(rect.Right - curveSize, rect.Y, curveSize, curveSize, 270, 90);
path.AddArc(rect.Right - curveSize, rect.Bottom - curveSize, curveSize, curveSize, 0, 90);
path.AddArc(rect.X, rect.Bottom - curveSize, curveSize, curveSize, 90, 90);
path.CloseFigure();
return path;
}
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
Rectangle rectSurface = this.ClientRectangle;
Rectangle rectBorder = Rectangle.Inflate(rectSurface, -borderSize, -borderSize);
int smoothSize = 2;
if (borderSize > 0)
smoothSize = borderSize;
if (borderRadius > 2) //Rounded button
{
using (GraphicsPath pathSurface = GetFigurePath(rectSurface, borderRadius))
using (GraphicsPath pathBorder = GetFigurePath(rectBorder, borderRadius - borderSize))
using (Pen penSurface = new Pen(this.Parent.BackColor, smoothSize))
using (Pen penBorder = new Pen(borderColor, borderSize))
{
pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
//Button surface
this.Region = new Region(pathSurface);
//Draw surface border for HD result
pevent.Graphics.DrawPath(penSurface, pathSurface);
//Button border
if (borderSize >= 1)
//Draw control border
pevent.Graphics.DrawPath(penBorder, pathBorder);
}
}
else //Normal button
{
pevent.Graphics.SmoothingMode = SmoothingMode.None;
//Button surface
this.Region = new Region(rectSurface);
//Button border
if (borderSize >= 1)
{
using (Pen penBorder = new Pen(borderColor, borderSize))
{
penBorder.Alignment = PenAlignment.Inset;
pevent.Graphics.DrawRectangle(penBorder, 0, 0, this.Width - 1, this.Height - 1);
}
}
}
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
this.Parent.BackColorChanged += new EventHandler(Container_BackColorChange);
}
private void Container_BackColorChange(object sender, EventArgs e)
{
if (this.DesignMode)
{
this.Invalidate();
}
}
private void InitializeComponent()
{
this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand();
this.SuspendLayout();
this.ResumeLayout(false);
}
}
}