-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCollapsiblePanelOld.cs
169 lines (134 loc) · 4.91 KB
/
CollapsiblePanelOld.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace OVT.CustomControls
{
public class CollapsiblePanelOld : System.Windows.Forms.Panel
{
public CollapsiblePanelOld()
{
InitializeComponent();
headerFont = new Font(Font, FontStyle.Bold);
headerTextColor = Color.Black;
}
private bool headerTextAutoEllipsis;
public bool HeaderTextAutoEllipsis
{
get { return headerTextAutoEllipsis; }
set
{
headerTextAutoEllipsis = value;
Refresh();
}
}
private string headerText;
public string HeaderText
{
get { return headerText; }
set
{
headerText = value;
Refresh();
}
}
private Color headerTextColor;
public Color HeaderTextColor
{
get { return headerTextColor; }
set
{
headerTextColor = value;
Refresh();
}
}
private Image headerImage;
public Image HeaderImage
{
get { return headerImage; }
set
{
headerImage = value;
Refresh();
}
}
private Font headerFont;
public Font HeaderFont
{
get { return headerFont; }
set
{
headerFont = value;
Refresh();
}
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
// Draw panel's header.
int headerRectHeight = e.ClipRectangle.Height / 3;
if (headerRectHeight > 40)
headerRectHeight = 40;
if (headerRectHeight < 30)
headerRectHeight = 30;
Rectangle headerRect = new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width,
headerRectHeight);
LinearGradientBrush headerBrush = new LinearGradientBrush(
headerRect.Location,
new Point(headerRect.X+headerRect.Width, headerRect.Y+headerRect.Height),
Color.Snow, Color.LightBlue);
e.Graphics.FillRectangle(headerBrush, headerRect);
// Draw header image.
if (headerImage != null)
{
Size headerImageSize = new Size(headerRectHeight,headerRectHeight);
Rectangle imageRect = new Rectangle(headerRect.Location, headerImageSize);
e.Graphics.DrawImage(headerImage, imageRect);
}
// Calculate header string position.
if (!String.IsNullOrEmpty(headerText))
{
int delta = 0;
if (headerImage != null)
{
delta = headerRectHeight;
}
PointF headerTextPosition = new PointF();
Size headerTextSize = TextRenderer.MeasureText(headerText, headerFont);
if (headerTextAutoEllipsis)
{
if (headerTextSize.Width >= headerRect.Width - delta)
{
RectangleF rectLayout =
new RectangleF((float)headerRect.X + delta, (float)(headerRect.Height - headerTextSize.Height) / 2, (float)headerRect.Width - delta, (float)headerTextSize.Height);
StringFormat format = new StringFormat();
format.Trimming = StringTrimming.EllipsisWord;
e.Graphics.DrawString(headerText, headerFont, new SolidBrush(headerTextColor),
rectLayout, format);
}
else
{
headerTextPosition.X = (delta + headerRect.Width - headerTextSize.Width) / 2;
headerTextPosition.Y = (headerRect.Height - headerTextSize.Height) / 2;
e.Graphics.DrawString(headerText, headerFont, new SolidBrush(headerTextColor),
headerTextPosition);
}
}
else
{
headerTextPosition.X = (delta + headerRect.Width - headerTextSize.Width) / 2;
headerTextPosition.Y = (headerRect.Height - headerTextSize.Height) / 2;
e.Graphics.DrawString(headerText, headerFont, new SolidBrush(headerTextColor),
headerTextPosition);
}
}
// Draw right button.
}
private void InitializeComponent()
{
this.SuspendLayout();
this.ResumeLayout(false);
}
}
}