-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPPPanel.cs
115 lines (104 loc) · 3.3 KB
/
GPPPanel.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
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 KustomKontrol
{
public class GPPPanel : Panel
{
//Field
private int borderRadius = 30;
private float gradientAngle = 90F;
private Color gradientTopColor = Color.DodgerBlue;
private Color gradientBottomColor = Color.CadetBlue;
//Contructor
public GPPPanel()
{
this.BackColor = Color.Transparent;
this.ForeColor = Color.Black;
this.Size = new Size(350, 200);
}
//Properties
public int BorderRadius
{
get
{
return borderRadius;
}
set
{
borderRadius = value; this.Invalidate();
}
}
public float GradientAngle
{
get
{
return gradientAngle;
}
set
{
gradientAngle = value; this.Invalidate();
}
}
public Color GradientTopColor
{
get
{
return gradientTopColor;
}
set
{
gradientTopColor = value; this.Invalidate();
}
}
public Color GradientBottomColor
{
get
{
return gradientBottomColor;
}
set
{
gradientBottomColor = value; this.Invalidate();
}
}
//Methods
private GraphicsPath GetAdioPath(RectangleF rectangle, float radius)
{
GraphicsPath graphicsPath = new GraphicsPath();
graphicsPath.StartFigure();
graphicsPath.AddArc(rectangle.Width - radius, rectangle.Height - radius, radius, radius, 0, 90);
graphicsPath.AddArc(rectangle.X, rectangle.Height - radius, radius, radius, 90, 90);
graphicsPath.AddArc(rectangle.X, rectangle.Y, radius, radius, 180, 90);
graphicsPath.AddArc(rectangle.Width - radius, rectangle.Y, radius, radius, 270, 90);
graphicsPath.CloseFigure();
return graphicsPath;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
//Gradients
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
LinearGradientBrush brushG = new LinearGradientBrush(this.ClientRectangle, this.GradientTopColor, this.GradientBottomColor, this.GradientAngle);
Graphics graphicsSegiG = e.Graphics;
graphicsSegiG.FillRectangle(brushG, ClientRectangle);
//Borders
RectangleF rectangleF = new RectangleF(0, 0, this.Width, this.Height);
if (borderRadius > 2)
{
using (GraphicsPath graphicsPath = GetAdioPath(rectangleF, borderRadius))
using (Pen pen = new Pen(this.Parent.BackColor, 2))
{
this.Region = new Region(graphicsPath);
e.Graphics.DrawPath(pen, graphicsPath);
}
}
else this.Region = new Region(rectangleF);
}
}
}