1
using
System;
2
3 using System.Collections.Generic;
4
5 using System.ComponentModel;
6
7 using System.Drawing;
8
9 using System.Data;
10
11 using System.Text;
12
13 using System.Windows.Forms;
14
15 using System.Drawing.Drawing2D;
16
17 using System.Threading;
18
19
20
21 namespace ShadePanelControl
22
23 {
24
25 public partial class ShadePanelControl : UserControl
26
27 {
28
29 private LinearGradientBrush lgBrush;
30
31 private Color startColor = Color.White;
32
33 private Color endColor = Color.Silver;
34
35 private Color frameColor = Color.Silver;
36
37 private string titleString = "标题一";
38
39 private int topPanelHeight = 20;
40
41 private Color titleStringColor = Color.Gray;
42
43 private bool beenExpand = false;
44
45 private int height;
46
47
48
49 public int Height1
50
51 {
52
53 get { return this.Height; }
54
55 set
56
57 {
58
59 this.Height = value;
60
61 height = value;
62
63 this.Invalidate();
64
65 }
66
67 }
68
69
70
71 [Category("TitleStringColor"), Description("标题颜色")]
72
73 public Color TitleStringColor
74
75 {
76
77 get { return titleStringColor; }
78
79 set
80
81 {
82
83 titleStringColor = value;
84
85 this.Invalidate();
86
87 }
88
89 }
90
91
92
93
94
95 Arribute Set Or Get#region Arribute Set Or Get
96
97 [Category("TopPanelHeight"), Description("标题高度")]
98
99 public int TopPanelHeight
100
101 {
102
103 get { return topPanelHeight; }
104
105 set
106
107 {
108
109 topPanelHeight = value;
110
111 panel_Top.Height = topPanelHeight;
112
113 this.Invalidate();
114
115 }
116
117 }
118
119 [Category("TitleString"), Description("标题")]
120
121 public string TitleString
122
123 {
124
125 get { return titleString; }
126
127 set
128
129 {
130
131 titleString = value;
132
133 this.Invalidate();
134
135 }
136
137 }
138
139 [Category("FrameColor"), Description("边框线的颜色")]
140
141 public Color FrameColor
142
143 {
144
145 get { return frameColor; }
146
147 set
148
149 {
150
151 frameColor = value;
152
153 this.Invalidate();
154
155 }
156
157 }
158
159
160
161 [Category("EndColor"), Description("Panel的结束颜色")]
162
163 public Color EndColor
164
165 {
166
167 get { return endColor; }
168
169 set
170
171 {
172
173 endColor = value;
174
175 this.Invalidate();
176
177 }
178
179 }
180
181
182
183 [Category("StartColor"), Description("Panel的起始颜色")]
184
185 public Color StartColor
186
187 {
188
189 get { return startColor; }
190
191 set
192
193 {
194
195 startColor = value;
196
197 this.Invalidate();
198
199 }
200
201 }
202
203 #endregion
204
205 public ShadePanelControl()
206
207 {
208
209 InitializeComponent();
210
211 this.height = this.Height;
212
213 }
214
215 protected override void OnPaint(PaintEventArgs e)
216
217 {
218
219 DrawPanel(e.Graphics);
220
221 DrawSolidLine(e.Graphics);
222
223 DrawTitleString(e.Graphics);
224
225 base.OnPaint(e);
226
227 }
228
229
230
231 /**//// <summary>
232
233 /// 绘制渐变框
234
235 /// </summary>
236
237 /// <param name="g"></param>
238
239 private void DrawPanel(Graphics g)
240
241 {
242
243 Rectangle rect = new Rectangle(0, 0, this.Width, topPanelHeight);
244
245 lgBrush = new LinearGradientBrush(rect, startColor, endColor,
246
247 LinearGradientMode.Vertical);
248
249 g.FillRectangle(lgBrush, rect);
250
251 }
252
253 /**//// <summary>
254
255 /// 绘制边框线
256
257 /// </summary>
258
259 /// <param name="g"></param>
260
261 private void DrawSolidLine(Graphics g)
262
263 {
264
265 Rectangle rec = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
266
267 Pen pen = new Pen(frameColor, 1);
268
269 g.DrawRectangle(pen, rec);
270
271 pen.Dispose();
272
273 }
274
275 /**//// <summary>
276
277 ///绘制PANEL_MAIN的边框
278
279 /// </summary>
280
281 /// <param name="sender"></param>
282
283 /// <param name="e"></param>
284
285 private void panel_Main_Paint(object sender, PaintEventArgs e)
286
287 {
288
289 Rectangle rec = new Rectangle(0, 0, panel_Main.Width - 1, panel_Main.Height - 1);
290
291 Pen pen = new Pen(frameColor, 1);
292
293 e.Graphics.DrawRectangle(pen, rec);
294
295 pen.Dispose();
296
297 }
298
299 /**//// <summary>
300
301 /// 绘制标题文本
302
303 /// </summary>
304
305 /// <param name="g"></param>
306
307 private void DrawTitleString(Graphics g)
308
309 {
310
311 Font font = new Font("宋体", 9);
312
313 int offset = (panel_Top.Height - 9) / 2;
314
315 Rectangle rec = new Rectangle(5, offset, this.panel_Top.Width - 10, 20);
316
317 g.DrawString(titleString, font, new SolidBrush(titleStringColor), rec);
318
319 font.Dispose();
320
321 }
322
323 /**//// <summary>
324
325 /// 主面板收缩或展开
326
327 /// </summary>
328
329 private void Expand()
330
331 {
332
333 if (!beenExpand)
334
335 {
336
337 this.Height -= this.height - panel_Top.Height;
338
339 pictureBox1.Image = global::ShadePanelControl.Resource1.Expand2;
340
341 beenExpand = true;
342
343 this.Invalidate();
344
345 }
346
347 else
348
349 {
350
351 this.Height += this.height - panel_Top.Height;
352
353 pictureBox1.Image = global::ShadePanelControl.Resource1.Expand;
354
355 this.Invalidate();
356
357 beenExpand = false;
358
359 }
360
361 }
362
363
364
365 private void panel_Top_Click(object sender, EventArgs e)
366
367 {
368
369 Expand();
370
371 }
372
373 }
374
375}
376
2
3 using System.Collections.Generic;
4
5 using System.ComponentModel;
6
7 using System.Drawing;
8
9 using System.Data;
10
11 using System.Text;
12
13 using System.Windows.Forms;
14
15 using System.Drawing.Drawing2D;
16
17 using System.Threading;
18
19
20
21 namespace ShadePanelControl
22
23 {
24
25 public partial class ShadePanelControl : UserControl
26
27 {
28
29 private LinearGradientBrush lgBrush;
30
31 private Color startColor = Color.White;
32
33 private Color endColor = Color.Silver;
34
35 private Color frameColor = Color.Silver;
36
37 private string titleString = "标题一";
38
39 private int topPanelHeight = 20;
40
41 private Color titleStringColor = Color.Gray;
42
43 private bool beenExpand = false;
44
45 private int height;
46
47
48
49 public int Height1
50
51 {
52
53 get { return this.Height; }
54
55 set
56
57 {
58
59 this.Height = value;
60
61 height = value;
62
63 this.Invalidate();
64
65 }
66
67 }
68
69
70
71 [Category("TitleStringColor"), Description("标题颜色")]
72
73 public Color TitleStringColor
74
75 {
76
77 get { return titleStringColor; }
78
79 set
80
81 {
82
83 titleStringColor = value;
84
85 this.Invalidate();
86
87 }
88
89 }
90
91
92
93
94
95 Arribute Set Or Get#region Arribute Set Or Get
96
97 [Category("TopPanelHeight"), Description("标题高度")]
98
99 public int TopPanelHeight
100
101 {
102
103 get { return topPanelHeight; }
104
105 set
106
107 {
108
109 topPanelHeight = value;
110
111 panel_Top.Height = topPanelHeight;
112
113 this.Invalidate();
114
115 }
116
117 }
118
119 [Category("TitleString"), Description("标题")]
120
121 public string TitleString
122
123 {
124
125 get { return titleString; }
126
127 set
128
129 {
130
131 titleString = value;
132
133 this.Invalidate();
134
135 }
136
137 }
138
139 [Category("FrameColor"), Description("边框线的颜色")]
140
141 public Color FrameColor
142
143 {
144
145 get { return frameColor; }
146
147 set
148
149 {
150
151 frameColor = value;
152
153 this.Invalidate();
154
155 }
156
157 }
158
159
160
161 [Category("EndColor"), Description("Panel的结束颜色")]
162
163 public Color EndColor
164
165 {
166
167 get { return endColor; }
168
169 set
170
171 {
172
173 endColor = value;
174
175 this.Invalidate();
176
177 }
178
179 }
180
181
182
183 [Category("StartColor"), Description("Panel的起始颜色")]
184
185 public Color StartColor
186
187 {
188
189 get { return startColor; }
190
191 set
192
193 {
194
195 startColor = value;
196
197 this.Invalidate();
198
199 }
200
201 }
202
203 #endregion
204
205 public ShadePanelControl()
206
207 {
208
209 InitializeComponent();
210
211 this.height = this.Height;
212
213 }
214
215 protected override void OnPaint(PaintEventArgs e)
216
217 {
218
219 DrawPanel(e.Graphics);
220
221 DrawSolidLine(e.Graphics);
222
223 DrawTitleString(e.Graphics);
224
225 base.OnPaint(e);
226
227 }
228
229
230
231 /**//// <summary>
232
233 /// 绘制渐变框
234
235 /// </summary>
236
237 /// <param name="g"></param>
238
239 private void DrawPanel(Graphics g)
240
241 {
242
243 Rectangle rect = new Rectangle(0, 0, this.Width, topPanelHeight);
244
245 lgBrush = new LinearGradientBrush(rect, startColor, endColor,
246
247 LinearGradientMode.Vertical);
248
249 g.FillRectangle(lgBrush, rect);
250
251 }
252
253 /**//// <summary>
254
255 /// 绘制边框线
256
257 /// </summary>
258
259 /// <param name="g"></param>
260
261 private void DrawSolidLine(Graphics g)
262
263 {
264
265 Rectangle rec = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
266
267 Pen pen = new Pen(frameColor, 1);
268
269 g.DrawRectangle(pen, rec);
270
271 pen.Dispose();
272
273 }
274
275 /**//// <summary>
276
277 ///绘制PANEL_MAIN的边框
278
279 /// </summary>
280
281 /// <param name="sender"></param>
282
283 /// <param name="e"></param>
284
285 private void panel_Main_Paint(object sender, PaintEventArgs e)
286
287 {
288
289 Rectangle rec = new Rectangle(0, 0, panel_Main.Width - 1, panel_Main.Height - 1);
290
291 Pen pen = new Pen(frameColor, 1);
292
293 e.Graphics.DrawRectangle(pen, rec);
294
295 pen.Dispose();
296
297 }
298
299 /**//// <summary>
300
301 /// 绘制标题文本
302
303 /// </summary>
304
305 /// <param name="g"></param>
306
307 private void DrawTitleString(Graphics g)
308
309 {
310
311 Font font = new Font("宋体", 9);
312
313 int offset = (panel_Top.Height - 9) / 2;
314
315 Rectangle rec = new Rectangle(5, offset, this.panel_Top.Width - 10, 20);
316
317 g.DrawString(titleString, font, new SolidBrush(titleStringColor), rec);
318
319 font.Dispose();
320
321 }
322
323 /**//// <summary>
324
325 /// 主面板收缩或展开
326
327 /// </summary>
328
329 private void Expand()
330
331 {
332
333 if (!beenExpand)
334
335 {
336
337 this.Height -= this.height - panel_Top.Height;
338
339 pictureBox1.Image = global::ShadePanelControl.Resource1.Expand2;
340
341 beenExpand = true;
342
343 this.Invalidate();
344
345 }
346
347 else
348
349 {
350
351 this.Height += this.height - panel_Top.Height;
352
353 pictureBox1.Image = global::ShadePanelControl.Resource1.Expand;
354
355 this.Invalidate();
356
357 beenExpand = false;
358
359 }
360
361 }
362
363
364
365 private void panel_Top_Click(object sender, EventArgs e)
366
367 {
368
369 Expand();
370
371 }
372
373 }
374
375}
376
以下是运行的界面,里面的容器还没有加上去,有兴趣的朋友自己加下。。