一个自绘的导航栏控件
一个自绘的导航栏控件,类似WINDOWS的左侧导航栏
1using System;
2
3using System.Collections.Generic;
4
5using System.ComponentModel;
6
7using System.Drawing;
8
9using System.Data;
10
11using System.Text;
12
13using System.Windows.Forms;
14
15using System.Drawing.Drawing2D;
16
17using System.Threading;
18
19
20
21namespace 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
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
3using System.Collections.Generic;
4
5using System.ComponentModel;
6
7using System.Drawing;
8
9using System.Data;
10
11using System.Text;
12
13using System.Windows.Forms;
14
15using System.Drawing.Drawing2D;
16
17using System.Threading;
18
19
20
21namespace 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
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
以下是运行的界面,里面的容器还没有加上去,有兴趣的朋友自己加下。。