forked from menees/Libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtendedPanel.cs
More file actions
138 lines (115 loc) · 3.12 KB
/
ExtendedPanel.cs
File metadata and controls
138 lines (115 loc) · 3.12 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
namespace Menees.Windows.Forms
{
#region Using Directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
#endregion
/// <summary>
/// A panel container that can paint a themed border.
/// </summary>
/// <remarks>
/// This is useful for containing a RichTextBox that has its BorderStyle set to None.
/// RichTextBox doesn't support a themed border in .NET, but if you set the RichTextBox's
/// border to None and embed it in an ExtendedPanel with UseVisualStyleBorder
/// set to true then it at least appears to use a themed border.
/// </remarks>
public sealed class ExtendedPanel : Panel
{
#region Private Data Members
private bool useVisualStyleBorder;
#endregion
#region Constructors
/// <summary>
/// Creates a new instance.
/// </summary>
public ExtendedPanel()
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.UseVisualStyleBorder = true;
}
#endregion
#region Public Properties
/// <summary>
/// Gets or sets whether the panel should use a themed border if the BorderStyle is None.
/// </summary>
[DefaultValue(true)]
[Description("Whether the panel should use a themed border if the BorderStyle is None.")]
public bool UseVisualStyleBorder
{
get
{
return this.useVisualStyleBorder && this.BorderStyle == BorderStyle.None;
}
set
{
if (this.useVisualStyleBorder != value)
{
this.useVisualStyleBorder = value;
this.Invalidate();
}
this.UpdateVisualStyleProperties();
}
}
#endregion
#region Protected Methods
/// <summary>
/// Handles the custom painting for the control.
/// </summary>
/// <param name="e">The paint event arguments.</param>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.UseVisualStyleBorder)
{
Rectangle rectClient = this.ClientRectangle;
Rectangle rectBorder = new Rectangle(rectClient.X, rectClient.Y, rectClient.Width - 1, rectClient.Height - 1);
if (Application.RenderWithVisualStyles)
{
ControlPaint.DrawVisualStyleBorder(e.Graphics, rectBorder);
}
else
{
ControlPaint.DrawBorder3D(e.Graphics, rectBorder, Border3DStyle.Sunken);
}
}
}
/// <summary>
/// Called when the system colors change.
/// </summary>
/// <param name="e">The event arguments.</param>
protected override void OnSystemColorsChanged(EventArgs e)
{
base.OnSystemColorsChanged(e);
this.UpdateVisualStyleProperties();
this.Invalidate();
}
#endregion
#region Private Methods
private void UpdateVisualStyleProperties()
{
if (this.useVisualStyleBorder)
{
if (Application.RenderWithVisualStyles)
{
this.Padding = new Padding(SystemInformation.BorderSize.Width);
}
else
{
Size sz = SystemInformation.Border3DSize;
this.Padding = new Padding(sz.Width, sz.Height, sz.Width + 1, sz.Height + 1);
}
this.BorderStyle = BorderStyle.None;
}
else
{
this.Padding = Padding.Empty;
}
}
#endregion
}
}