Files
@ f2c2ba4ef3d4
Branch filter:
Location: seniordesign-ui/Demo.WindowsForms/BSE.Windows.Forms/XPander/XPanderPanel.cs
f2c2ba4ef3d4
38.2 KiB
text/x-csharp
Removed unneeded code and verified use of functions. project is essentially
complete except for some live testing and cache testing/experiments
complete except for some live testing and cache testing/experiments
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 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 | using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;
using System.ComponentModel.Design;
using Demo.WindowsForms.Properties;
namespace BSE.Windows.Forms
{
#region Class XPanderPanel
/// <summary>
/// Used to group collections of controls.
/// </summary>
/// <remarks>
/// XPanderPanel controls represent the expandable and collapsable panels in XPanderPanelList.
/// The XpanderPanel is a control that contains other controls.
/// You can use a XPanderPanel to group collections of controls such as the XPanderPanelList.
/// The order of xpanderpanels in the XPanderPanelList.XPanderPanels collection reflects the order
/// of xpanderpanels controls. To change the order of tabs in the control, you must change
/// their positions in the collection by removing them and inserting them at new indexes.
/// You can change the xpanderpanel's appearance. For example, to make it appear flat,
/// set the CaptionStyle property to CaptionStyle.Flat.
/// On top of the XPanderPanel there is the captionbar.
/// This captionbar may contain an image and text. According to it's properties the panel is closable.
/// </remarks>
/// <copyright>Copyright © 2006-2008 Uwe Eichkorn
/// 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.
/// </copyright>
[Designer(typeof(XPanderPanelDesigner))]
[DesignTimeVisible(false)]
public partial class XPanderPanel : BasePanel
{
#region EventsPublic
/// <summary>
/// The CaptionStyleChanged event occurs when CaptionStyle flags have been changed.
/// </summary>
[Description("The CaptionStyleChanged event occurs when CaptionStyle flags have been changed.")]
public event EventHandler<EventArgs> CaptionStyleChanged;
#endregion
#region Constants
#endregion
#region FieldsPrivate
private System.Drawing.Image m_imageChevron;
private System.Drawing.Image m_imageChevronUp;
private System.Drawing.Image m_imageChevronDown;
private CustomXPanderPanelColors m_customColors;
private System.Drawing.Image m_imageClosePanel;
private bool m_bIsClosable = true;
private CaptionStyle m_captionStyle;
#endregion
#region Properties
/// <summary>
/// Gets or sets a value indicating whether the expand icon in a XPanderPanel is visible.
/// </summary>
[Description("Gets or sets a value indicating whether the expand icon in a XPanderPanel is visible.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[DefaultValue(false)]
[Browsable(false)]
[Category("Appearance")]
public override bool ShowExpandIcon
{
get
{
return base.ShowExpandIcon;
}
set
{
base.ShowExpandIcon = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether the close icon in a XPanderPanel is visible.
/// </summary>
[Description("Gets or sets a value indicating whether the close icon in a XPanderPanel is visible.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[DefaultValue(false)]
[Browsable(false)]
[Category("Appearance")]
public override bool ShowCloseIcon
{
get
{
return base.ShowCloseIcon;
}
set
{
base.ShowCloseIcon = value;
}
}
/// <summary>
/// Gets the custom colors which are used for the XPanderPanel.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Description("The custom colors which are used for the XPanderPanel.")]
[Category("Appearance")]
public CustomXPanderPanelColors CustomColors
{
get
{
return this.m_customColors;
}
}
/// <summary>
/// Gets or sets the style of the caption (not for PanelStyle.Aqua).
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
public CaptionStyle CaptionStyle
{
get
{
return this.m_captionStyle;
}
set
{
if(value.Equals(this.m_captionStyle) == false)
{
this.m_captionStyle = value;
OnCaptionStyleChanged(this, EventArgs.Empty);
}
}
}
/// <summary>
/// Gets or sets a value indicating whether this XPanderPanel is closable.
/// </summary>
[Description("Gets or sets a value indicating whether this XPanderPanel is closable.")]
[DefaultValue(true)]
[Category("Appearance")]
public bool IsClosable
{
get
{
return this.m_bIsClosable;
}
set
{
if(value.Equals(this.m_bIsClosable) == false)
{
this.m_bIsClosable = value;
this.Invalidate(false);
}
}
}
/// <summary>
/// Gets or sets the height and width of the XPanderPanel.
/// </summary>
[Browsable(false)]
public new Size Size
{
get
{
return base.Size;
}
set
{
base.Size = value;
}
}
#endregion
#region MethodsPublic
/// <summary>
/// Initializes a new instance of the XPanderPanel class.
/// </summary>
public XPanderPanel()
{
InitializeComponent();
this.BackColor = Color.Transparent;
this.CaptionStyle = CaptionStyle.Normal;
this.ForeColor = SystemColors.ControlText;
this.Height = this.CaptionHeight;
this.ShowBorder = true;
this.m_customColors = new CustomXPanderPanelColors();
this.m_customColors.CustomColorsChanged += OnCustomColorsChanged;
}
/// <summary>
/// Gets the rectangle that represents the display area of the XPanderPanel.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Rectangle DisplayRectangle
{
get
{
Padding padding = this.Padding;
Rectangle displayRectangle = new Rectangle(
padding.Left + Constants.BorderThickness,
padding.Top + this.CaptionHeight,
this.ClientRectangle.Width - padding.Left - padding.Right - (2 * Constants.BorderThickness),
this.ClientRectangle.Height - this.CaptionHeight - padding.Top - padding.Bottom);
if(this.Controls.Count > 0)
{
XPanderPanelList xpanderPanelList = this.Controls[0] as XPanderPanelList;
if((xpanderPanelList != null) && (xpanderPanelList.Dock == DockStyle.Fill))
{
displayRectangle = new Rectangle(
padding.Left,
padding.Top + this.CaptionHeight,
this.ClientRectangle.Width - padding.Left - padding.Right,
this.ClientRectangle.Height - this.CaptionHeight - padding.Top - padding.Bottom - Constants.BorderThickness);
}
}
return displayRectangle;
}
}
#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);
base.BackColor = Color.Transparent;
Color backColor = this.PanelColors.XPanderPanelBackColor;
if((backColor != Color.Empty) && backColor != Color.Transparent)
{
Rectangle rectangle = new Rectangle(
0,
this.CaptionHeight,
this.ClientRectangle.Width,
this.ClientRectangle.Height - this.CaptionHeight);
using(SolidBrush backgroundBrush = new SolidBrush(backColor))
{
pevent.Graphics.FillRectangle(backgroundBrush, rectangle);
}
}
}
/// <summary>
/// Raises the Paint event.
/// </summary>
/// <param name="e">A PaintEventArgs that contains the event data.</param>
protected override void OnPaint(PaintEventArgs e)
{
if(IsZeroWidthOrHeight(this.CaptionRectangle) == true)
{
return;
}
using(UseAntiAlias antiAlias = new UseAntiAlias(e.Graphics))
{
Graphics graphics = e.Graphics;
using(UseClearTypeGridFit clearTypeGridFit = new UseClearTypeGridFit(graphics))
{
bool bExpand = this.Expand;
bool bShowBorder = this.ShowBorder;
Color borderColor = this.PanelColors.BorderColor;
Rectangle borderRectangle = this.ClientRectangle;
switch(this.PanelStyle)
{
case PanelStyle.Default:
case PanelStyle.Office2007:
DrawCaptionbar(graphics, bExpand, bShowBorder, this.PanelStyle);
CalculatePanelHeights();
DrawBorders(graphics, this);
break;
}
}
}
}
/// <summary>
/// Raises the PanelExpanding event.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">A XPanderStateChangeEventArgs that contains the event data.</param>
protected override void OnPanelExpanding(object sender, XPanderStateChangeEventArgs e)
{
bool bExpand = e.Expand;
if(bExpand == true)
{
this.Expand = bExpand;
this.Invalidate(false);
}
base.OnPanelExpanding(sender, e);
}
/// <summary>
/// Raises the CaptionStyleChanged event.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">An EventArgs that contains the event data.</param>
protected virtual void OnCaptionStyleChanged(object sender, EventArgs e)
{
this.Invalidate(this.CaptionRectangle);
if(this.CaptionStyleChanged != null)
{
this.CaptionStyleChanged(sender, e);
}
}
/// <summary>
/// Raises the MouseUp event.
/// </summary>
/// <param name="e">A MouseEventArgs that contains data about the OnMouseUp event.</param>
protected override void OnMouseUp(MouseEventArgs e)
{
if(this.CaptionRectangle.Contains(e.X, e.Y) == true)
{
if((this.ShowCloseIcon == false) && (this.ShowExpandIcon == false))
{
OnExpandClick(this, EventArgs.Empty);
}
else if((this.ShowCloseIcon == true) && (this.ShowExpandIcon == false))
{
if(this.RectangleCloseIcon.Contains(e.X, e.Y) == false)
{
OnExpandClick(this, EventArgs.Empty);
}
}
if(this.ShowExpandIcon == true)
{
if(this.RectangleExpandIcon.Contains(e.X, e.Y) == true)
{
OnExpandClick(this, EventArgs.Empty);
}
}
if((this.ShowCloseIcon == true) && (this.m_bIsClosable == true))
{
if(this.RectangleCloseIcon.Contains(e.X, e.Y) == true)
{
OnCloseClick(this, EventArgs.Empty);
}
}
}
}
/// <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 DrawCaptionbar(Graphics graphics, bool bExpand, bool bShowBorder, PanelStyle panelStyle)
{
Rectangle captionRectangle = this.CaptionRectangle;
Color colorGradientBegin = this.PanelColors.XPanderPanelCaptionGradientBegin;
Color colorGradientEnd = this.PanelColors.XPanderPanelCaptionGradientEnd;
Color colorGradientMiddle = this.PanelColors.XPanderPanelCaptionGradientMiddle;
Color colorText = this.PanelColors.XPanderPanelCaptionText;
Color foreColorCloseIcon = this.PanelColors.XPanderPanelCaptionCloseIcon;
Color foreColorExpandIcon = this.PanelColors.XPanderPanelCaptionExpandIcon;
bool bHover = this.HoverStateCaptionBar == HoverState.Hover ? true : false;
if(this.m_imageClosePanel == null)
{
this.m_imageClosePanel = Resources.closePanel;
}
if(this.m_imageChevronUp == null)
{
this.m_imageChevronUp = Resources.ChevronUp;
}
if(this.m_imageChevronDown == null)
{
this.m_imageChevronDown = Resources.ChevronDown;
}
this.m_imageChevron = this.m_imageChevronDown;
if(bExpand == true)
{
this.m_imageChevron = this.m_imageChevronUp;
}
if(this.m_captionStyle == CaptionStyle.Normal)
{
if(bHover == true)
{
colorGradientBegin = this.PanelColors.XPanderPanelSelectedCaptionBegin;
colorGradientEnd = this.PanelColors.XPanderPanelSelectedCaptionEnd;
colorGradientMiddle = this.PanelColors.XPanderPanelSelectedCaptionMiddle;
if(bExpand == true)
{
colorGradientBegin = this.PanelColors.XPanderPanelPressedCaptionBegin;
colorGradientEnd = this.PanelColors.XPanderPanelPressedCaptionEnd;
colorGradientMiddle = this.PanelColors.XPanderPanelPressedCaptionMiddle;
}
colorText = this.PanelColors.XPanderPanelSelectedCaptionText;
foreColorCloseIcon = colorText;
foreColorExpandIcon = colorText;
}
else
{
if(bExpand == true)
{
colorGradientBegin = this.PanelColors.XPanderPanelCheckedCaptionBegin;
colorGradientEnd = this.PanelColors.XPanderPanelCheckedCaptionEnd;
colorGradientMiddle = this.PanelColors.XPanderPanelCheckedCaptionMiddle;
colorText = this.PanelColors.XPanderPanelSelectedCaptionText;
foreColorCloseIcon = colorText;
foreColorExpandIcon = colorText;
}
}
if(panelStyle != PanelStyle.Office2007)
{
RenderDoubleBackgroundGradient(
graphics,
captionRectangle,
colorGradientBegin,
colorGradientMiddle,
colorGradientEnd,
LinearGradientMode.Vertical,
false);
}
else
{
RenderButtonBackground(
graphics,
captionRectangle,
colorGradientBegin,
colorGradientMiddle,
colorGradientEnd);
}
}
else
{
Color colorFlatGradientBegin = this.PanelColors.XPanderPanelFlatCaptionGradientBegin;
Color colorFlatGradientEnd = this.PanelColors.XPanderPanelFlatCaptionGradientEnd;
Color colorInnerBorder = this.PanelColors.InnerBorderColor;
colorText = this.PanelColors.XPanderPanelCaptionText;
foreColorExpandIcon = colorText;
RenderFlatButtonBackground(graphics, captionRectangle, colorFlatGradientBegin, colorFlatGradientEnd, bHover);
DrawInnerBorders(graphics, this);
}
DrawImagesAndText(
graphics,
captionRectangle,
CaptionSpacing,
this.ImageRectangle,
this.Image,
this.RightToLeft,
this.m_bIsClosable,
this.ShowCloseIcon,
this.m_imageClosePanel,
foreColorCloseIcon,
ref this.RectangleCloseIcon,
this.ShowExpandIcon,
this.m_imageChevron,
foreColorExpandIcon,
ref this.RectangleExpandIcon,
this.CaptionFont,
colorText,
this.Text);
}
private static void DrawBorders(Graphics graphics, XPanderPanel xpanderPanel)
{
if(xpanderPanel.ShowBorder == true)
{
using(GraphicsPath graphicsPath = new GraphicsPath())
{
using(Pen borderPen = new Pen(xpanderPanel.PanelColors.BorderColor, Constants.BorderThickness))
{
Rectangle captionRectangle = xpanderPanel.CaptionRectangle;
Rectangle borderRectangle = captionRectangle;
if(xpanderPanel.Expand == true)
{
borderRectangle = xpanderPanel.ClientRectangle;
graphics.DrawLine(
borderPen,
captionRectangle.Left,
captionRectangle.Top + captionRectangle.Height - Constants.BorderThickness,
captionRectangle.Left + captionRectangle.Width,
captionRectangle.Top + captionRectangle.Height - Constants.BorderThickness);
}
XPanderPanelList xpanderPanelList = xpanderPanel.Parent as XPanderPanelList;
if((xpanderPanelList != null) && (xpanderPanelList.Dock == DockStyle.Fill))
{
BSE.Windows.Forms.Panel panel = xpanderPanelList.Parent as BSE.Windows.Forms.Panel;
XPanderPanel parentXPanderPanel = xpanderPanelList.Parent as XPanderPanel;
if(((panel != null) && (panel.Padding == new Padding(0))) ||
((parentXPanderPanel != null) && (parentXPanderPanel.Padding == new Padding(0))))
{
if(xpanderPanel.Top != 0)
{
graphicsPath.AddLine(
borderRectangle.Left,
borderRectangle.Top,
borderRectangle.Left + captionRectangle.Width,
borderRectangle.Top);
}
// Left vertical borderline
graphics.DrawLine(borderPen,
borderRectangle.Left,
borderRectangle.Top,
borderRectangle.Left,
borderRectangle.Top + borderRectangle.Height);
// Right vertical borderline
graphics.DrawLine(borderPen,
borderRectangle.Left + borderRectangle.Width - Constants.BorderThickness,
borderRectangle.Top,
borderRectangle.Left + borderRectangle.Width - Constants.BorderThickness,
borderRectangle.Top + borderRectangle.Height);
}
else
{
// Upper horizontal borderline only at the top xpanderPanel
if(xpanderPanel.Top == 0)
{
graphicsPath.AddLine(
borderRectangle.Left,
borderRectangle.Top,
borderRectangle.Left + borderRectangle.Width,
borderRectangle.Top);
}
// Left vertical borderline
graphicsPath.AddLine(
borderRectangle.Left,
borderRectangle.Top,
borderRectangle.Left,
borderRectangle.Top + borderRectangle.Height);
//Lower horizontal borderline
graphicsPath.AddLine(
borderRectangle.Left,
borderRectangle.Top + borderRectangle.Height - Constants.BorderThickness,
borderRectangle.Left + borderRectangle.Width - Constants.BorderThickness,
borderRectangle.Top + borderRectangle.Height - Constants.BorderThickness);
// Right vertical borderline
graphicsPath.AddLine(
borderRectangle.Left + borderRectangle.Width - Constants.BorderThickness,
borderRectangle.Top,
borderRectangle.Left + borderRectangle.Width - Constants.BorderThickness,
borderRectangle.Top + borderRectangle.Height);
}
}
else
{
// Upper horizontal borderline only at the top xpanderPanel
if(xpanderPanel.Top == 0)
{
graphicsPath.AddLine(
borderRectangle.Left,
borderRectangle.Top,
borderRectangle.Left + borderRectangle.Width,
borderRectangle.Top);
}
// Left vertical borderline
graphicsPath.AddLine(
borderRectangle.Left,
borderRectangle.Top,
borderRectangle.Left,
borderRectangle.Top + borderRectangle.Height);
//Lower horizontal borderline
graphicsPath.AddLine(
borderRectangle.Left,
borderRectangle.Top + borderRectangle.Height - Constants.BorderThickness,
borderRectangle.Left + borderRectangle.Width - Constants.BorderThickness,
borderRectangle.Top + borderRectangle.Height - Constants.BorderThickness);
// Right vertical borderline
graphicsPath.AddLine(
borderRectangle.Left + borderRectangle.Width - Constants.BorderThickness,
borderRectangle.Top,
borderRectangle.Left + borderRectangle.Width - Constants.BorderThickness,
borderRectangle.Top + borderRectangle.Height);
}
}
using(Pen borderPen = new Pen(xpanderPanel.PanelColors.BorderColor, Constants.BorderThickness))
{
graphics.DrawPath(borderPen, graphicsPath);
}
}
}
}
private static void DrawInnerBorders(Graphics graphics, XPanderPanel xpanderPanel)
{
if(xpanderPanel.ShowBorder == true)
{
using(GraphicsPath graphicsPath = new GraphicsPath())
{
Rectangle captionRectangle = xpanderPanel.CaptionRectangle;
XPanderPanelList xpanderPanelList = xpanderPanel.Parent as XPanderPanelList;
if((xpanderPanelList != null) && (xpanderPanelList.Dock == DockStyle.Fill))
{
BSE.Windows.Forms.Panel panel = xpanderPanelList.Parent as BSE.Windows.Forms.Panel;
XPanderPanel parentXPanderPanel = xpanderPanelList.Parent as XPanderPanel;
if(((panel != null) && (panel.Padding == new Padding(0))) ||
((parentXPanderPanel != null) && (parentXPanderPanel.Padding == new Padding(0))))
{
//Left vertical borderline
graphicsPath.AddLine(captionRectangle.X, captionRectangle.Y + captionRectangle.Height, captionRectangle.X, captionRectangle.Y + Constants.BorderThickness);
if(xpanderPanel.Top == 0)
{
//Upper horizontal borderline
graphicsPath.AddLine(captionRectangle.X, captionRectangle.Y, captionRectangle.X + captionRectangle.Width, captionRectangle.Y);
}
else
{
//Upper horizontal borderline
graphicsPath.AddLine(captionRectangle.X, captionRectangle.Y + Constants.BorderThickness, captionRectangle.X + captionRectangle.Width, captionRectangle.Y + Constants.BorderThickness);
}
}
}
else
{
//Left vertical borderline
graphicsPath.AddLine(captionRectangle.X + Constants.BorderThickness, captionRectangle.Y + captionRectangle.Height, captionRectangle.X + Constants.BorderThickness, captionRectangle.Y);
if(xpanderPanel.Top == 0)
{
//Upper horizontal borderline
graphicsPath.AddLine(captionRectangle.X + Constants.BorderThickness, captionRectangle.Y + Constants.BorderThickness, captionRectangle.X + captionRectangle.Width - Constants.BorderThickness, captionRectangle.Y + Constants.BorderThickness);
}
else
{
//Upper horizontal borderline
graphicsPath.AddLine(captionRectangle.X + Constants.BorderThickness, captionRectangle.Y, captionRectangle.X + captionRectangle.Width - Constants.BorderThickness, captionRectangle.Y);
}
}
using(Pen borderPen = new Pen(xpanderPanel.PanelColors.InnerBorderColor))
{
graphics.DrawPath(borderPen, graphicsPath);
}
}
}
}
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) && (xpanderPanel.Visible == true))
{
iPanelHeight += xpanderPanel.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
+ xpanderPanel.CaptionHeight
- iPanelHeight;
}
else
{
xpanderPanel.Height = xpanderPanel.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) && (xpanderPanel.Visible == true))
{
xpanderPanel.Top = iTop;
iTop += xpanderPanel.Height;
}
}
}
#endregion
}
#endregion
#region Class XPanderPanelDesigner
/// <summary>
/// Designer class for extending the design mode behavior of a XPanderPanel control
/// </summary>
internal class XPanderPanelDesigner : System.Windows.Forms.Design.ScrollableControlDesigner
{
#region FieldsPrivate
private Pen m_borderPen = new Pen(Color.FromKnownColor(KnownColor.ControlDarkDark));
private System.Windows.Forms.Design.Behavior.Adorner m_adorner;
#endregion
#region MethodsPublic
/// <summary>
/// Initializes a new instance of the XPanderPanelDesigner class.
/// </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);
XPanderPanel xpanderPanel = Control as XPanderPanel;
if(xpanderPanel != null)
{
this.m_adorner = new System.Windows.Forms.Design.Behavior.Adorner();
BehaviorService.Adorners.Add(this.m_adorner);
this.m_adorner.Glyphs.Add(new XPanderPanelCaptionGlyph(BehaviorService, xpanderPanel));
}
}
#endregion
#region MethodsProtected
/// <summary>
/// Releases the unmanaged resources used by the XPanderPanelDesigner,
/// and optionally releases the managed resources.
/// </summary>
/// <param name="disposing">true to release both managed and unmanaged resources;
/// false to release only unmanaged resources.</param>
protected override void Dispose(bool disposing)
{
try
{
if(disposing)
{
if(this.m_borderPen != null)
{
this.m_borderPen.Dispose();
}
if(this.m_adorner != null)
{
if(BehaviorService != null)
{
BehaviorService.Adorners.Remove(this.m_adorner);
}
}
}
}
finally
{
base.Dispose(disposing);
}
}
/// <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("BackColor");
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");
}
#endregion
}
#endregion
#region Class XPanderPanelCaptionGlyph
/// <summary>
/// Represents a single user interface (UI) entity managed by an Adorner.
/// </summary>
internal class XPanderPanelCaptionGlyph : System.Windows.Forms.Design.Behavior.Glyph
{
#region FieldsPrivate
private XPanderPanel m_xpanderPanel;
private System.Windows.Forms.Design.Behavior.BehaviorService m_behaviorService;
#endregion
#region Properties
/// <summary>
/// Gets the bounds of the Glyph.
/// </summary>
public override Rectangle Bounds
{
get
{
Point edge = this.m_behaviorService.ControlToAdornerWindow(this.m_xpanderPanel);
Rectangle bounds = new Rectangle(
edge.X,
edge.Y,
this.m_xpanderPanel.Width,
this.m_xpanderPanel.CaptionHeight);
return bounds;
}
}
#endregion
#region MethodsPublic
/// <summary>
/// Initializes a new instance of the CaptionGlyph class.
/// </summary>
/// <param name="behaviorService"></param>
/// <param name="xpanderPanel"></param>
public XPanderPanelCaptionGlyph(System.Windows.Forms.Design.Behavior.BehaviorService behaviorService, XPanderPanel xpanderPanel)
:
base(new XPanderPanelCaptionClickBehavior(xpanderPanel))
{
this.m_behaviorService = behaviorService;
this.m_xpanderPanel = xpanderPanel;
}
/// <summary>
/// Provides hit test logic.
/// </summary>
/// <param name="p">A point to hit-test.</param>
/// <returns>A Cursor if the Glyph is associated with p; otherwise, a null reference</returns>
public override Cursor GetHitTest(Point p)
{
// GetHitTest is called to see if the point is
// within this glyph. This gives us a chance to decide
// what cursor to show. Returning null from here means
// the mouse pointer is not currently inside of the glyph.
// Returning a valid cursor here indicates the pointer is
// inside the glyph, and also enables our Behavior property
// as the active behavior.
if((this.m_xpanderPanel != null) && (this.m_xpanderPanel.Expand == false) && (Bounds.Contains(p)))
{
return Cursors.Hand;
}
return null;
}
/// <summary>
/// Provides paint logic.
/// </summary>
/// <param name="pe">A PaintEventArgs that contains the event data.</param>
public override void Paint(PaintEventArgs pe)
{
}
#endregion
}
#endregion
#region Class XPanderPanelCaptionClickBehavior
/// <summary>
/// Designer behaviour when the user clicks in the glyph on the XPanderPanel caption
/// </summary>
internal class XPanderPanelCaptionClickBehavior : System.Windows.Forms.Design.Behavior.Behavior
{
#region FieldsPrivate
private XPanderPanel m_xpanderPanel;
#endregion
#region MethodsPublic
/// <summary>
/// Initializes a new instance of the Behavior class.
/// </summary>
/// <param name="xpanderPanel">XPanderPanel for this behaviour</param>
public XPanderPanelCaptionClickBehavior(XPanderPanel xpanderPanel)
{
this.m_xpanderPanel = xpanderPanel;
}
/// <summary>
/// Called when any mouse-down message enters the adorner window of the BehaviorService.
/// </summary>
/// <param name="g">A Glyph.</param>
/// <param name="button">A MouseButtons value indicating which button was clicked.</param>
/// <param name="mouseLoc">The location at which the click occurred.</param>
/// <returns>true if the message was handled; otherwise, false. </returns>
public override bool OnMouseDown(System.Windows.Forms.Design.Behavior.Glyph g, MouseButtons button, Point mouseLoc)
{
if((this.m_xpanderPanel != null) && (this.m_xpanderPanel.Expand == false))
{
XPanderPanelList xpanderPanelList = this.m_xpanderPanel.Parent as XPanderPanelList;
if(xpanderPanelList != null)
{
xpanderPanelList.Expand(this.m_xpanderPanel);
this.m_xpanderPanel.Invalidate(false);
}
}
return true; // indicating we processed this event.
}
#endregion
}
#endregion
}
|