-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoundedGroupBox.cs
More file actions
70 lines (68 loc) · 2.89 KB
/
RoundedGroupBox.cs
File metadata and controls
70 lines (68 loc) · 2.89 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
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
// Copyright © Charlie Howard 2026 All rights reserved.
namespace PlutoPoint_Installer
{
public class RoundedGroupBox : GroupBox
{
public int CornerRadius { get; set; } = 3;
public Color BorderColor { get; set; } = Color.Silver;
public Color? BorderColorOverride { get; set; } = null;
public Color? TextColorOverride { get; set; } = null;
public float BorderThickness { get; set; } = 2f;
public int BorderShadowTop { get; set; } = 26;
public int BorderShadowBottom { get; set; } = 77;
public RoundedGroupBox()
{
SetStyle(ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.SupportsTransparentBackColor, true);
BackColor = Color.Transparent;
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
int topPadding = 7;
int bottomPadding = 7;
SizeF textSize = e.Graphics.MeasureString(Text, Font);
RectangleF textRect = new RectangleF(
(ClientRectangle.Width - textSize.Width) / 2f - 4,
0,
textSize.Width + 8,
textSize.Height
);
Rectangle rect = new Rectangle(
0,
topPadding,
ClientRectangle.Width - 1,
ClientRectangle.Height - topPadding - bottomPadding
);
using (GraphicsPath path = new GraphicsPath())
{
int dia = CornerRadius * 2;
path.AddArc(rect.X, rect.Y, dia, dia, 180, 90);
path.AddArc(rect.Right - dia, rect.Y, dia, dia, 270, 90);
path.AddArc(rect.Right - dia, rect.Bottom - dia, dia, dia, 0, 90);
path.AddArc(rect.X, rect.Bottom - dia, dia, dia, 90, 90);
path.CloseFigure();
Region oldClip = e.Graphics.Clip;
e.Graphics.SetClip(textRect, CombineMode.Exclude);
using (LinearGradientBrush borderBrush = new LinearGradientBrush(
rect,
Color.FromArgb(BorderShadowTop, 0, 0, 0),
Color.FromArgb(BorderShadowBottom, 0, 0, 0),
LinearGradientMode.Vertical))
{
using (Pen pen = new Pen(borderBrush, BorderThickness))
e.Graphics.DrawPath(pen, path);
}
e.Graphics.Clip = oldClip;
}
using (SolidBrush textBrush = new SolidBrush(TextColorOverride ?? ForeColor))
e.Graphics.DrawString(Text, Font, textBrush, textRect.X + 4, textRect.Y);
}
}
}