实例介绍
【实例简介】
跟XP系统左侧可折叠式菜单一样,可以折叠、展开,可以自己定义颜色,自己研究吧,非常有用的一个源码,样式和outlook左侧菜单差不多!我自己就在用,我用在erp项目里面,哈哈,很爽啊,大概步骤: 1.在你的解决方案里添加“现有项目”,找到BSE.Windows.Forms添加进去→2.在你自己的工程里面引用刚才添加的项目→3.运行一下,完成,在左边工具箱中就有啦。大概过程就是这样,反正死活就是要先引用。
【实例截图】
跟XP系统左侧可折叠式菜单一样,可以折叠、展开,可以自己定义颜色,自己研究吧,非常有用的一个源码,样式和outlook左侧菜单差不多!我自己就在用,我用在erp项目里面,哈哈,很爽啊,大概步骤: 1.在你的解决方案里添加“现有项目”,找到BSE.Windows.Forms添加进去→2.在你自己的工程里面引用刚才添加的项目→3.运行一下,完成,在左边工具箱中就有啦。大概过程就是这样,反正死活就是要先引用。
【实例截图】
【核心代码】
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | using System; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Drawing; using System.Drawing.Drawing2D; using System.Data; using System.Windows.Forms; using System.ComponentModel.Design; namespace BSE.Windows.Forms { #region Partial class XPanderPanel /// <summary> /// Used to group collections of controls. /// </summary> /// <remarks> /// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY /// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE /// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR /// PURPOSE. IT CAN BE DISTRIBUTED FREE OF CHARGE AS LONG AS THIS HEADER /// REMAINS UNCHANGED. /// </remarks> /// <copyright>Copyright ?2006-2007 Uwe Eichkorn</copyright> [Designer( typeof (XPanderPanelDesigner))] [DesignTimeVisible( false )] public partial class XPanderPanel : BasePanel { #region EventsPublic /// <summary> /// Occurs when the caption of the xpanderpanel is clicked. /// </summary> [Description( "Occurs when the caption of the xpanderpanel is clicked." )] public event EventHandler<XPanderPanelClickEventArgs> CaptionClick; #endregion #region Constants #endregion #region FieldsPrivate private BSE.Windows.Forms.PanelStyle m_ePanelStyle; private System.Drawing.Image m_imageChevron; private System.Drawing.Image m_imageChevronUp; private System.Drawing.Image m_imageChevronDown; private Color m_colorChevron; private bool m_bExpand; #endregion #region Properties /// <summary> /// Gets or sets the caption style in this xpanderpanel. /// </summary> [DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden)] public override BSE.Windows.Forms.PanelStyle PanelStyle { get { return this .m_ePanelStyle;} set { if (value != this .m_ePanelStyle) { this .m_ePanelStyle = value; this .Invalidate(); } } } /// <summary> /// The foreground color of this component, which is used to display the caption text. /// </summary> [Description( "The foreground color of this component, which is used to display the caption text." )] [DefaultValue( typeof (SystemColors), "System.Drawing.SystemColors.ActiveCaptionText" )] [Category( "Appearance" )] public override Color CaptionForeColor { get { return base .CaptionForeColor; } set { if (value != base .CaptionForeColor) { base .CaptionForeColor = value; this .m_colorChevron = Color.FromArgb(255, Math.Min(255, ( int )(( float )( base .CaptionForeColor.R) / ( float )(1.01))), Math.Min(255, ( int )(( float )( base .CaptionForeColor.G) / ( float )(1.01))), Math.Min(255, ( int )(( float )( base .CaptionForeColor.B) / ( float )(1.01)))); this .Invalidate( this .CaptionRectangle); } } } /// <summary> /// Expands this xpanderpanel in it's xpanderpanellist /// </summary> [Description( "Expand this XpanderPanel" )] [DefaultValue( false )] [Category( "Appearance" )] public bool Expand { get { return this .m_bExpand;} set { if (value != this .m_bExpand) { this .m_bExpand = value; if ( this .DesignMode == true ) { if ( this .m_bExpand == true ) { if ( this .CaptionClick != null ) { this .CaptionClick( this , new XPanderPanelClickEventArgs( this .m_bExpand)); } } } this .Invalidate(); } } } internal Color ChevronColor { get { return this .m_colorChevron; } } #endregion #region MethodsPublic /// <summary> /// Initializes a new instance of the XPanderPanel class. /// </summary> public XPanderPanel() { InitializeComponent(); this .CaptionForeColor = SystemColors.ControlText; this .BackColor = SystemColors.Window; this .ForeColor = SystemColors.ControlText; this .DockPadding.Top = this .CaptionHeight; this .Height = this .CaptionHeight; this .ShowBorder = true ; this .m_imageChevronUp = global::BSE.Windows.Forms.Properties.Resources.chevron_up; this .m_imageChevronDown = global::BSE.Windows.Forms.Properties.Resources.chevron_down; } #endregion #region MethodsProtected /// <summary> /// Paints the background of the control. /// </summary> /// <param name="pevent">A PaintEventArgs that contains information about the control to paint.</param> protected override void OnPaintBackground(PaintEventArgs pevent) { base .OnPaintBackground(pevent); } /// <summary> /// Raises the Paint event. /// </summary> /// <param name="e">A PaintEventArgs that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { base .OnPaint(e); switch ( this .m_ePanelStyle) { case PanelStyle.None: case PanelStyle.Default: DrawStyleDefault(e); CalculatePanelHeights(); DrawBorder(e); break ; case PanelStyle.Aqua: DrawStyleAqua(e); CalculatePanelHeights(); break ; } } /// <summary> /// Raises the OnMouseMove event. /// </summary> /// <param name="e">A MouseEventArgs that contains the event data.</param> protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) { base .OnMouseMove(e); //Change cursor to hand when mouse moves over caption area. if (e.Y <= this .CaptionHeight) { Cursor.Current = Cursors.Hand; } else { Cursor.Current = Cursors.Default; } } /// <summary> /// Raises the MouseDown event. /// </summary> /// <param name="e">A MouseEventArgs that contains data about the OnMouseDown event.</param> protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) { base .OnMouseDown(e); //Don't do anything if did not click on caption. if (e.Y > this .CaptionHeight) { return ; } if ( this .m_bExpand == false ) { this .m_bExpand = true ; if ( this .CaptionClick != null ) { this .CaptionClick( this , new BSE.Windows.Forms.XPanderPanelClickEventArgs( this .m_bExpand)); } } } /// <summary> /// Raises the VisibleChanged event. /// </summary> /// <param name="e">An EventArgs that contains the event data.</param> protected override void OnVisibleChanged(EventArgs e) { base .OnVisibleChanged(e); if ( this .DesignMode == true ) { return ; } if ( this .Visible == false ) { if ( this .Expand == true ) { this .Expand = false ; foreach (Control control in this .Parent.Controls) { BSE.Windows.Forms.XPanderPanel xpanderPanel = control as BSE.Windows.Forms.XPanderPanel; if (xpanderPanel != null ) { if (xpanderPanel.Visible == true ) { xpanderPanel.Expand = true ; return ; } } } } } #if DEBUG //System.Diagnostics.Trace.WriteLine("Visibility: " this.Name this.Visible); #endif CalculatePanelHeights(); } #endregion #region MethodsPrivate private void DrawStyleDefault(PaintEventArgs e) { Rectangle rectangle = this .CaptionRectangle; Color colorGradientBegin = ProfessionalColors.ToolStripGradientBegin; Color colorGradientMiddle = ProfessionalColors.ToolStripGradientMiddle; Color colorGradientEnd = ProfessionalColors.ToolStripGradientEnd; if ( this .ColorScheme == ColorScheme.Custom) { colorGradientBegin = this .ColorCaptionGradientBegin; colorGradientMiddle = this .ColorCaptionGradientMiddle; colorGradientEnd = this .ColorCaptionGradientEnd; } if ( this .m_bExpand == true ) { if ( this .ColorScheme == ColorScheme.Professional) { colorGradientBegin = ProfessionalColors.ButtonCheckedGradientBegin; colorGradientMiddle = ProfessionalColors.ButtonCheckedGradientMiddle; colorGradientEnd = ProfessionalColors.ButtonCheckedGradientEnd; } this .m_imageChevron = this .m_imageChevronUp; } else { this .m_imageChevron = this .m_imageChevronDown; } RenderDoubleBackgroundGradient( e.Graphics, rectangle, colorGradientBegin, colorGradientMiddle, colorGradientEnd, LinearGradientMode.Vertical, false ); int iTextPositionX = CaptionSpacing; if ( this .Image != null ) { Rectangle imageRectangle = this .ImageRectangle; if ( this .RightToLeft == RightToLeft.No) { DrawImage(e.Graphics, this .Image, imageRectangle); iTextPositionX = this .ImageSize.Width CaptionSpacing; } else { imageRectangle.X = rectangle.Right - RightImagePositionX; DrawImage(e.Graphics, this .Image, imageRectangle); } } Rectangle textRectangle = rectangle; textRectangle.X = iTextPositionX; textRectangle.Width -= iTextPositionX CaptionSpacing; if ( this .RightToLeft == RightToLeft.Yes) { if ( this .Image != null ) { textRectangle.Width -= RightImagePositionX; } } DrawString(e.Graphics, textRectangle, this .CaptionFont, this .CaptionForeColor, this .Text, this .RightToLeft); if ( this .ShowBorder == true ) { if ( this .Expand == true ) { using (SolidBrush borderBrush = new SolidBrush(System.Windows.Forms.ProfessionalColors.ToolStripBorder)) { using (Pen borderPen = new Pen(borderBrush, 1)) { e.Graphics.DrawLine( borderPen, this .ClientRectangle.Left, this .CaptionHeight, this .ClientRectangle.Width, this .CaptionHeight); } } } } } private void DrawStyleAqua(PaintEventArgs e) { Color colorGradientBegin = ProfessionalColors.ToolStripGradientBegin; Color colorGradientEnd = ProfessionalColors.ToolStripGradientEnd; if ( this .ColorScheme == ColorScheme.Custom) { colorGradientBegin = this .ColorCaptionGradientBegin; colorGradientEnd = this .ColorCaptionGradientEnd; } // defines the chevron direction if ( this .m_bExpand == true ) { this .m_imageChevron = this .m_imageChevronUp; } else { this .m_imageChevron = this .m_imageChevronDown; } Rectangle outerRectangle = this .CaptionRectangle; using (GraphicsPath outerRectangleGraphicsPath = GetBackgroundPath(outerRectangle, 20)) { using (LinearGradientBrush outerLinearGradientBrush = new LinearGradientBrush( outerRectangle, colorGradientBegin, colorGradientEnd, LinearGradientMode.Vertical)) { e.Graphics.FillPath(outerLinearGradientBrush, outerRectangleGraphicsPath); //draw top bubble } } // // Create top water color to give "aqua" effect // Rectangle innerRectangle = outerRectangle; innerRectangle.Height = 14; using (GraphicsPath innerRectangleGraphicsPath = GetPath(innerRectangle, 20)) { using (LinearGradientBrush innerRectangleBrush = new LinearGradientBrush( innerRectangle, Color.FromArgb(255, Color.White), Color.FromArgb(32, Color.White), LinearGradientMode.Vertical)) { // // draw shapes // e.Graphics.FillPath(innerRectangleBrush, innerRectangleGraphicsPath); //draw top bubble } } //DrawImage int iTextPositionX1 = CaptionSpacing; Rectangle imageRectangleLeft = this .ImageRectangle; if (RightToLeft == RightToLeft.No) { if ( this .Image != null ) { DrawImage(e.Graphics, this .Image, imageRectangleLeft); iTextPositionX1 = this .ImageSize.Width CaptionSpacing; } } else { DrawChevron(e.Graphics, this .m_imageChevron,imageRectangleLeft, this .ChevronColor); iTextPositionX1 = this .ImageSize.Width CaptionSpacing; } // // Draw Caption text // Rectangle textRectangle = outerRectangle; textRectangle.X = iTextPositionX1; textRectangle.Width = outerRectangle.Width - textRectangle.X - RightImagePositionX - CaptionSpacing; int iTextPositionX2 = outerRectangle.Right - RightImagePositionX; Rectangle imageRectangleRight = this .ImageRectangle; imageRectangleRight.X = iTextPositionX2; if (RightToLeft == RightToLeft.No) { DrawChevron(e.Graphics, this .m_imageChevron, imageRectangleRight, this .ChevronColor); } else { if ( this .Image != null ) { DrawImage(e.Graphics, this .Image, imageRectangleRight); } else { textRectangle.Width = CaptionSpacing this .ImageSize.Width; } } DrawString(e.Graphics, textRectangle, this .CaptionFont, this .CaptionForeColor, this .Text, this .RightToLeft); } private void DrawBorder(PaintEventArgs e) { if ( this .ShowBorder == true ) { Rectangle borderRectangle = this .ClientRectangle; borderRectangle.Inflate(0, 1); borderRectangle.Offset(0, -1); ControlPaint.DrawBorder( e.Graphics, borderRectangle, System.Windows.Forms.ProfessionalColors.ToolStripBorder, ButtonBorderStyle.Solid); } } private void CalculatePanelHeights() { if ( this .Parent == null ) { return ; } int iPanelHeight = this .Parent.Padding.Top; foreach (Control control in this .Parent.Controls) { BSE.Windows.Forms.XPanderPanel xpanderPanel = control as BSE.Windows.Forms.XPanderPanel; if (xpanderPanel != null ) { if (xpanderPanel.Visible == true ) { iPanelHeight = this .CaptionHeight; } } } iPanelHeight = this .Parent.Padding.Bottom; foreach (Control control in this .Parent.Controls) { BSE.Windows.Forms.XPanderPanel xpanderPanel = control as BSE.Windows.Forms.XPanderPanel; if (xpanderPanel != null ) { if (xpanderPanel.Expand == true ) { xpanderPanel.Height = this .Parent.Height this .CaptionHeight - iPanelHeight; } else { xpanderPanel.Height = this .CaptionHeight; } } } int iTop = this .Parent.Padding.Top; foreach (Control control in this .Parent.Controls) { BSE.Windows.Forms.XPanderPanel xpanderPanel = control as BSE.Windows.Forms.XPanderPanel; if (xpanderPanel != null ) { if (xpanderPanel.Visible == true ) { xpanderPanel.Top = iTop; iTop = xpanderPanel.Height; } } } } #endregion } #endregion #region Class XPanderPanelDesigner internal class XPanderPanelDesigner : System.Windows.Forms.Design.ScrollableControlDesigner { #region FieldsPrivate private Pen m_BorderPen = new Pen(Color.FromKnownColor(KnownColor.ControlDarkDark)); #endregion #region MethodsPublic /// <summary> /// /// </summary> public XPanderPanelDesigner() { this .m_BorderPen.DashStyle = DashStyle.Dash; } /// <summary> /// Initializes the designer with the specified component. /// </summary> /// <param name="component">The IComponent to associate with the designer.</param> public override void Initialize(IComponent component) { base .Initialize(component); } /// <summary> /// Gets the selection rules that indicate the movement capabilities of a component. /// </summary> public override System.Windows.Forms.Design.SelectionRules SelectionRules { get { System.Windows.Forms.Design.SelectionRules selectionRules = System.Windows.Forms.Design.SelectionRules.None; return selectionRules; } } #endregion #region MethodsProtected /// <summary> /// Receives a call when the control that the designer is managing has painted its surface so the designer can /// paint any additional adornments on top of the xpanderpanel. /// </summary> /// <param name="e">A PaintEventArgs the designer can use to draw on the xpanderpanel.</param> protected override void OnPaintAdornments(PaintEventArgs e) { base .OnPaintAdornments(e); e.Graphics.DrawRectangle( this .m_BorderPen, 0, 0, this .Control.Width - 2, this .Control.Height - 2); } /// <summary> /// Allows a designer to change or remove items from the set of properties that it exposes through a <see cref="TypeDescriptor">TypeDescriptor</see>. /// </summary> /// <param name="properties">The properties for the class of the component.</param> protected override void PostFilterProperties(IDictionary properties) { base .PostFilterProperties(properties); properties.Remove( "AccessibilityObject" ); properties.Remove( "AccessibleDefaultActionDescription" ); properties.Remove( "AccessibleDescription" ); properties.Remove( "AccessibleName" ); properties.Remove( "AccessibleRole" ); properties.Remove( "AllowDrop" ); properties.Remove( "Anchor" ); properties.Remove( "AntiAliasing" ); properties.Remove( "AutoScroll" ); properties.Remove( "AutoScrollMargin" ); properties.Remove( "AutoScrollMinSize" ); properties.Remove( "BackgroundImage" ); properties.Remove( "BackgroundImageLayout" ); properties.Remove( "CausesValidation" ); properties.Remove( "ContextMenuStrip" ); properties.Remove( "Dock" ); properties.Remove( "GenerateMember" ); properties.Remove( "ImeMode" ); properties.Remove( "Location" ); properties.Remove( "MaximumSize" ); properties.Remove( "MinimumSize" ); properties.Remove( "Size" ); } #endregion } #endregion } |
好例子网口号:伸出你的我的手 — 分享!
相关软件
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)