一个自绘的导航栏控件

一个自绘的导航栏控件,类似WINDOWS的左侧导航栏

 

  1 None.gif using  System;
  2 None.gif
  3 None.gif using  System.Collections.Generic;
  4 None.gif
  5 None.gif using  System.ComponentModel;
  6 None.gif
  7 None.gif using  System.Drawing;
  8 None.gif
  9 None.gif using  System.Data;
 10 None.gif
 11 None.gif using  System.Text;
 12 None.gif
 13 None.gif using  System.Windows.Forms;
 14 None.gif
 15 None.gif using  System.Drawing.Drawing2D;
 16 None.gif
 17 None.gif using  System.Threading;
 18 None.gif
 19 None.gif 
 20 None.gif
 21 None.gif namespace  ShadePanelControl
 22 None.gif
 23 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 24InBlock.gif
 25InBlock.gif    public partial class ShadePanelControl : UserControl
 26InBlock.gif
 27ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 28InBlock.gif
 29InBlock.gif        private LinearGradientBrush lgBrush;
 30InBlock.gif
 31InBlock.gif        private Color startColor = Color.White;
 32InBlock.gif
 33InBlock.gif        private Color endColor = Color.Silver;
 34InBlock.gif
 35InBlock.gif        private Color frameColor = Color.Silver;
 36InBlock.gif
 37InBlock.gif        private string titleString = "标题一";
 38InBlock.gif
 39InBlock.gif        private int topPanelHeight = 20;
 40InBlock.gif
 41InBlock.gif        private Color titleStringColor = Color.Gray;
 42InBlock.gif
 43InBlock.gif        private bool beenExpand = false;
 44InBlock.gif
 45InBlock.gif        private int height;
 46InBlock.gif
 47InBlock.gif 
 48InBlock.gif
 49InBlock.gif        public int Height1
 50InBlock.gif
 51ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 52InBlock.gif
 53ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn this.Height; }
 54InBlock.gif
 55InBlock.gif            set
 56InBlock.gif
 57ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 58InBlock.gif
 59InBlock.gif                this.Height = value;
 60InBlock.gif
 61InBlock.gif                height = value;
 62InBlock.gif
 63InBlock.gif                this.Invalidate();
 64InBlock.gif
 65ExpandedSubBlockEnd.gif            }

 66InBlock.gif
 67ExpandedSubBlockEnd.gif        }

 68InBlock.gif
 69InBlock.gif 
 70InBlock.gif
 71InBlock.gif        [Category("TitleStringColor"), Description("标题颜色")]
 72InBlock.gif
 73InBlock.gif        public Color TitleStringColor
 74InBlock.gif
 75ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 76InBlock.gif
 77ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn titleStringColor; }
 78InBlock.gif
 79InBlock.gif            set
 80InBlock.gif
 81ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 82InBlock.gif
 83InBlock.gif                titleStringColor = value;
 84InBlock.gif
 85InBlock.gif                this.Invalidate();
 86InBlock.gif
 87ExpandedSubBlockEnd.gif            }

 88InBlock.gif
 89ExpandedSubBlockEnd.gif        }

 90InBlock.gif
 91InBlock.gif 
 92InBlock.gif
 93InBlock.gif 
 94InBlock.gif
 95ContractedSubBlock.gifExpandedSubBlockStart.gif        Arribute Set Or Get#region Arribute Set Or Get
 96InBlock.gif
 97InBlock.gif        [Category("TopPanelHeight"), Description("标题高度")]
 98InBlock.gif
 99InBlock.gif        public int TopPanelHeight
100InBlock.gif
101ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
102InBlock.gif
103ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn topPanelHeight; }
104InBlock.gif
105InBlock.gif            set
106InBlock.gif
107ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
108InBlock.gif
109InBlock.gif                topPanelHeight = value;
110InBlock.gif
111InBlock.gif                panel_Top.Height = topPanelHeight;
112InBlock.gif
113InBlock.gif                this.Invalidate();
114InBlock.gif
115ExpandedSubBlockEnd.gif            }

116InBlock.gif
117ExpandedSubBlockEnd.gif        }

118InBlock.gif
119InBlock.gif        [Category("TitleString"), Description("标题")]
120InBlock.gif
121InBlock.gif        public string TitleString
122InBlock.gif
123ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
124InBlock.gif
125ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn titleString; }
126InBlock.gif
127InBlock.gif            set
128InBlock.gif
129ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
130InBlock.gif
131InBlock.gif                titleString = value;
132InBlock.gif
133InBlock.gif                this.Invalidate();
134InBlock.gif
135ExpandedSubBlockEnd.gif            }

136InBlock.gif
137ExpandedSubBlockEnd.gif        }

138InBlock.gif
139InBlock.gif        [Category("FrameColor"), Description("边框线的颜色")]
140InBlock.gif
141InBlock.gif        public Color FrameColor
142InBlock.gif
143ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
144InBlock.gif
145ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn frameColor; }
146InBlock.gif
147InBlock.gif            set
148InBlock.gif
149ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
150InBlock.gif
151InBlock.gif                frameColor = value;
152InBlock.gif
153InBlock.gif                this.Invalidate();
154InBlock.gif
155ExpandedSubBlockEnd.gif            }

156InBlock.gif
157ExpandedSubBlockEnd.gif        }

158InBlock.gif
159InBlock.gif 
160InBlock.gif
161InBlock.gif        [Category("EndColor"), Description("Panel的结束颜色")]
162InBlock.gif
163InBlock.gif        public Color EndColor
164InBlock.gif
165ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
166InBlock.gif
167ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn endColor; }
168InBlock.gif
169InBlock.gif            set
170InBlock.gif
171ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
172InBlock.gif
173InBlock.gif                endColor = value;
174InBlock.gif
175InBlock.gif                this.Invalidate();
176InBlock.gif
177ExpandedSubBlockEnd.gif            }

178InBlock.gif
179ExpandedSubBlockEnd.gif        }

180InBlock.gif
181InBlock.gif 
182InBlock.gif
183InBlock.gif        [Category("StartColor"), Description("Panel的起始颜色")]
184InBlock.gif
185InBlock.gif        public Color StartColor
186InBlock.gif
187ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
188InBlock.gif
189ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn startColor; }
190InBlock.gif
191InBlock.gif            set
192InBlock.gif
193ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
194InBlock.gif
195InBlock.gif                startColor = value;
196InBlock.gif
197InBlock.gif                this.Invalidate();
198InBlock.gif
199ExpandedSubBlockEnd.gif            }

200InBlock.gif
201ExpandedSubBlockEnd.gif        }

202InBlock.gif
203ExpandedSubBlockEnd.gif        #endregion

204InBlock.gif
205InBlock.gif        public ShadePanelControl()
206InBlock.gif
207ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
208InBlock.gif
209InBlock.gif            InitializeComponent();
210InBlock.gif
211InBlock.gif            this.height = this.Height;
212InBlock.gif
213ExpandedSubBlockEnd.gif        }

214InBlock.gif
215InBlock.gif        protected override void OnPaint(PaintEventArgs e)
216InBlock.gif
217ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
218InBlock.gif
219InBlock.gif            DrawPanel(e.Graphics);
220InBlock.gif
221InBlock.gif            DrawSolidLine(e.Graphics);
222InBlock.gif
223InBlock.gif            DrawTitleString(e.Graphics);
224InBlock.gif
225InBlock.gif            base.OnPaint(e);
226InBlock.gif
227ExpandedSubBlockEnd.gif        }

228InBlock.gif
229InBlock.gif 
230InBlock.gif
231ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
232InBlock.gif
233InBlock.gif        /// 绘制渐变框
234InBlock.gif
235InBlock.gif        /// </summary>
236InBlock.gif
237ExpandedSubBlockEnd.gif        /// <param name="g"></param>

238InBlock.gif
239InBlock.gif        private void DrawPanel(Graphics g)
240InBlock.gif
241ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
242InBlock.gif
243InBlock.gif            Rectangle rect = new Rectangle(00this.Width, topPanelHeight);
244InBlock.gif
245InBlock.gif            lgBrush = new LinearGradientBrush(rect, startColor, endColor,
246InBlock.gif
247InBlock.gif                 LinearGradientMode.Vertical);
248InBlock.gif
249InBlock.gif            g.FillRectangle(lgBrush, rect);
250InBlock.gif
251ExpandedSubBlockEnd.gif        }

252InBlock.gif
253ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
254InBlock.gif
255InBlock.gif        /// 绘制边框线
256InBlock.gif
257InBlock.gif        /// </summary>
258InBlock.gif
259ExpandedSubBlockEnd.gif        /// <param name="g"></param>

260InBlock.gif
261InBlock.gif        private void DrawSolidLine(Graphics g)
262InBlock.gif
263ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
264InBlock.gif
265InBlock.gif            Rectangle rec = new Rectangle(00this.Width - 1this.Height - 1);
266InBlock.gif
267InBlock.gif            Pen pen = new Pen(frameColor, 1);
268InBlock.gif
269InBlock.gif            g.DrawRectangle(pen, rec);
270InBlock.gif
271InBlock.gif            pen.Dispose();
272InBlock.gif
273ExpandedSubBlockEnd.gif        }

274InBlock.gif
275ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
276InBlock.gif
277InBlock.gif        ///绘制PANEL_MAIN的边框
278InBlock.gif
279InBlock.gif        /// </summary>
280InBlock.gif
281InBlock.gif        /// <param name="sender"></param>
282InBlock.gif
283ExpandedSubBlockEnd.gif        /// <param name="e"></param>

284InBlock.gif
285InBlock.gif        private void panel_Main_Paint(object sender, PaintEventArgs e)
286InBlock.gif
287ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
288InBlock.gif
289InBlock.gif            Rectangle rec = new Rectangle(00, panel_Main.Width - 1, panel_Main.Height - 1);
290InBlock.gif
291InBlock.gif            Pen pen = new Pen(frameColor, 1);
292InBlock.gif
293InBlock.gif            e.Graphics.DrawRectangle(pen, rec);
294InBlock.gif
295InBlock.gif            pen.Dispose();
296InBlock.gif
297ExpandedSubBlockEnd.gif        }

298InBlock.gif
299ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
300InBlock.gif
301InBlock.gif        /// 绘制标题文本
302InBlock.gif
303InBlock.gif        /// </summary>
304InBlock.gif
305ExpandedSubBlockEnd.gif        /// <param name="g"></param>

306InBlock.gif
307InBlock.gif        private void DrawTitleString(Graphics g)
308InBlock.gif
309ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
310InBlock.gif
311InBlock.gif            Font font = new Font("宋体"9);
312InBlock.gif
313InBlock.gif            int offset = (panel_Top.Height - 9/ 2;
314InBlock.gif
315InBlock.gif            Rectangle rec = new Rectangle(5, offset, this.panel_Top.Width - 1020);
316InBlock.gif
317InBlock.gif            g.DrawString(titleString, font, new SolidBrush(titleStringColor), rec);
318InBlock.gif
319InBlock.gif            font.Dispose();
320InBlock.gif
321ExpandedSubBlockEnd.gif        }

322InBlock.gif
323ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
324InBlock.gif
325InBlock.gif        /// 主面板收缩或展开
326InBlock.gif
327ExpandedSubBlockEnd.gif        /// </summary>

328InBlock.gif
329InBlock.gif        private void Expand()
330InBlock.gif
331ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
332InBlock.gif
333InBlock.gif            if (!beenExpand)
334InBlock.gif
335ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
336InBlock.gif
337InBlock.gif                this.Height -= this.height - panel_Top.Height;
338InBlock.gif
339InBlock.gif                pictureBox1.Image = global::ShadePanelControl.Resource1.Expand2;
340InBlock.gif
341InBlock.gif                beenExpand = true;
342InBlock.gif
343InBlock.gif                this.Invalidate();
344InBlock.gif
345ExpandedSubBlockEnd.gif            }

346InBlock.gif
347InBlock.gif            else
348InBlock.gif
349ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
350InBlock.gif
351InBlock.gif                this.Height += this.height - panel_Top.Height;
352InBlock.gif
353InBlock.gif                pictureBox1.Image = global::ShadePanelControl.Resource1.Expand;
354InBlock.gif
355InBlock.gif                this.Invalidate();
356InBlock.gif
357InBlock.gif                beenExpand = false;
358InBlock.gif
359ExpandedSubBlockEnd.gif            }

360InBlock.gif
361ExpandedSubBlockEnd.gif        }

362InBlock.gif
363InBlock.gif 
364InBlock.gif
365InBlock.gif        private void panel_Top_Click(object sender, EventArgs e)
366InBlock.gif
367ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
368InBlock.gif
369InBlock.gif            Expand();
370InBlock.gif
371ExpandedSubBlockEnd.gif        }

372InBlock.gif
373ExpandedSubBlockEnd.gif    }

374InBlock.gif
375ExpandedBlockEnd.gif}

376 None.gif


以下是运行的界面,里面的容器还没有加上去,有兴趣的朋友自己加下。。
ShadePic.JPG

转载于:https://www.cnblogs.com/wuweizhi/archive/2006/11/10/shuangfeiyan.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值