-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyGroupBox.cs
More file actions
80 lines (71 loc) · 2.44 KB
/
Copy pathMyGroupBox.cs
File metadata and controls
80 lines (71 loc) · 2.44 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NvkCommon
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
public partial class MyGroupBox : GroupBox
{
private Color _borderColor = Color.Black;
public Color BorderColor
{
get => _borderColor;
set
{
_borderColor = value;
Invalidate();
}
}
private bool _IsBoldBorder = false;
public bool IsBoldBorder
{
get
{
return _IsBoldBorder;
}
set
{
_IsBoldBorder = value;
Invalidate();
}
}
public MyGroupBox() : base()
{
}
protected override void OnPaint(PaintEventArgs e)
{
if (!IsBoldBorder)
{
base.OnPaint(e);
return;
}
// See GroupBox.OnPaint->GroupBoxRenderer.DrawGroupBox->GroupBoxRenderer.DrawThemedGroupBoxWithText...
int thickness = 3;
int halfThickness = thickness / 2;
Size tSize = TextRenderer.MeasureText(this.Text, this.Font);
Rectangle borderRect = e.ClipRectangle;
borderRect.Y += tSize.Height / 2;
borderRect.Height -= tSize.Height / 2;
using (Pen p = new Pen(BorderColor, thickness))
{
e.Graphics.DrawRectangle(p, new Rectangle(borderRect.X + halfThickness,
borderRect.Y,
borderRect.Width - thickness,
borderRect.Height - thickness));
}
// TODO: Improve this text rendering margin...
Rectangle textRect = e.ClipRectangle;
textRect.X += 8;
textRect.Width = tSize.Width + 3;
textRect.Height = tSize.Height;
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), textRect);
e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), textRect);
}
}
}