Files @ 65c134a3d619
Branch filter:

Location: seniordesign-ui/Demo.WindowsForms/BSE.Windows.Forms/XPander/Panel.cs

mkanning@CL-ENS241-10.cedarville.edu
Initial import of mapping source (huge commit)
   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
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using Demo.WindowsForms.Properties;
using System.Diagnostics;

namespace BSE.Windows.Forms
{
   #region Class Panel
   /// <summary>
   /// Used to group collections of controls. 
   /// </summary>
   /// <remarks>The Panel is a control that contains other controls.
   /// You can use a Panel to group collections of controls such as the XPanderPanelList control.
   /// On top of the Panel there is the captionbar. This captionbar may contain an image and text.
   /// According to it's dockstyle and properties the panel is collapsable and/or 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(PanelDesigner)),
   DesignTimeVisibleAttribute(true)]
   [DefaultEvent("CloseClick")]
   [ToolboxBitmap(typeof(System.Windows.Forms.Panel))]
   public partial class Panel : BasePanel
   {
      #region FieldsPrivate

      private Rectangle m_restoreBounds;
      private bool m_bShowTransparentBackground;
      private bool m_bShowXPanderPanelProfessionalStyle;
      private bool m_bShowCaptionbar;
      private LinearGradientMode m_linearGradientMode;
      private Image m_imageClosePanel;
      private CustomPanelColors m_customColors;
      private Image m_imgHoverBackground;
      private System.Windows.Forms.Splitter m_associatedSplitter;

      #endregion

      #region Properties
      /// <summary>
      /// Gets or sets the associated Splitter. If there is a splitter associated to a panel,
      /// the splitter visibility always changes when the visibilty of this panel changes.
      /// </summary>
      /// <value>The associated <see cref="Splitter"/></value>
      [Description("The associated Splitter.")]
      [Category("Behavior")]
      public virtual System.Windows.Forms.Splitter AssociatedSplitter
      {
         get
         {
            return this.m_associatedSplitter;
         }
         set
         {
            this.m_associatedSplitter = value;
         }
      }
      /// <summary>
      /// Gets the custom colors which are used for the panel.
      /// </summary>
      [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
      [Description("The custom colors which are used for the panel.")]
      [Category("Appearance")]
      public CustomPanelColors CustomColors
      {
         get
         {
            return this.m_customColors;
         }
      }
      /// <summary>
      /// Expands the panel.
      /// </summary>
      [Browsable(false)]
      [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
      public override bool Expand
      {
         get
         {
            return base.Expand;
         }
         set
         {
            base.Expand = value;
         }
      }
      /// <summary>
      /// LinearGradientMode of the panels background
      /// </summary>
      [Description("LinearGradientMode of the Panels background"),
      DefaultValue(1),
      Category("Appearance")]
      public LinearGradientMode LinearGradientMode
      {
         get
         {
            return this.m_linearGradientMode;
         }
         set
         {
            if(value.Equals(this.m_linearGradientMode) == false)
            {
               this.m_linearGradientMode = value;
               this.Invalidate(false);
            }
         }
      }
      /// <summary>
      /// Gets or sets a value indicating whether the panels captionbar is displayed.
      /// </summary>
      /// <example>
      /// <code>
      /// private void btnShowHideCaptionbar_Click(object sender, EventArgs e)
      /// {
      ///     //displaye or hides the captionbar at the top of the panel
      ///     panel6.ShowCaptionbar = !panel6.ShowCaptionbar;
      /// }
      /// </code>
      /// </example>
      [Description("A value indicating whether the panels captionbar is displayed.")]
      [DefaultValue(true)]
      [Category("Behavior")]
      public bool ShowCaptionbar
      {
         get
         {
            return this.m_bShowCaptionbar;
         }
         set
         {
            if(value.Equals(this.m_bShowCaptionbar) == false)
            {
               this.m_bShowCaptionbar = value;
               this.Invalidate(true);
            }
         }
      }
      /// <summary>
      /// Gets or sets a value indicating whether the controls background is transparent.
      /// </summary>
      [Description("Gets or sets a value indicating whether the controls background is transparent")]
      [DefaultValue(true)]
      [Category("Behavior")]
      public bool ShowTransparentBackground
      {
         get
         {
            return this.m_bShowTransparentBackground;
         }
         set
         {
            if(value.Equals(this.m_bShowTransparentBackground) == false)
            {
               this.m_bShowTransparentBackground = value;
               this.Invalidate(false);
            }
         }
      }
      /// <summary>
      /// Gets or sets a value indicating whether the controls caption professional colorscheme is the same then the XPanderPanels
      /// </summary>
      [Description("Gets or sets a value indicating whether the controls caption professional colorscheme is the same then the XPanderPanels")]
      [DefaultValue(false)]
      [Category("Behavior")]
      public bool ShowXPanderPanelProfessionalStyle
      {
         get
         {
            return this.m_bShowXPanderPanelProfessionalStyle;
         }
         set
         {
            if(value.Equals(this.m_bShowXPanderPanelProfessionalStyle) == false)
            {
               this.m_bShowXPanderPanelProfessionalStyle = value;
               this.Invalidate(false);
            }
         }
      }
      /// <summary>
      /// Gets the size and location of the panel in it's normal expanded state.
      /// </summary>
      /// <remarks>
      /// A Rect that specifies the size and location of a panel before being either collapsed
      /// </remarks>
      [Browsable(false)]
      public Rectangle RestoreBounds
      {
         get
         {
            return this.m_restoreBounds;
         }
      }
      #endregion

      #region MethodsPublic
      /// <summary>
      /// Initializes a new instance of the Panel class.
      /// </summary>
      public Panel()
      {
         InitializeComponent();

         this.CaptionFont = new Font(SystemFonts.CaptionFont.FontFamily, SystemFonts.CaptionFont.SizeInPoints + 2.75F, FontStyle.Bold);
         this.BackColor = Color.Transparent;
         this.ForeColor = SystemColors.ControlText;
         this.ShowTransparentBackground = true;
         this.ShowXPanderPanelProfessionalStyle = false;
         this.ColorScheme = ColorScheme.Professional;
         this.LinearGradientMode = LinearGradientMode.Vertical;
         this.Expand = true;
         this.CaptionHeight = 27;
         this.ImageSize = new Size(18, 18);
         this.m_bShowCaptionbar = true;
         this.m_customColors = new CustomPanelColors();
         this.m_customColors.CustomColorsChanged += OnCustomColorsChanged;
      }
      /// <summary>
      /// Sets the PanelProperties for the Panel
      /// </summary>
      /// <param name="panelColors">The PanelColors table</param>
      public override void SetPanelProperties(PanelColors panelColors)
      {
         this.m_imgHoverBackground = null;
         base.SetPanelProperties(panelColors);
      }
      /// <summary>
      /// Gets the rectangle that represents the display area of the Panel.
      /// </summary>
      [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
      public override Rectangle DisplayRectangle
      {
         get
         {
            Padding padding = this.Padding;
            Rectangle displayRectangle = new Rectangle(
                this.ClientRectangle.Left + padding.Left,
                this.ClientRectangle.Top + padding.Top,
                this.ClientRectangle.Width - padding.Left - padding.Right,
                this.ClientRectangle.Height - padding.Top - padding.Bottom);

            if(this.m_bShowCaptionbar == true)
            {
               if(this.Controls.Count > 0)
               {
                  XPanderPanelList xpanderPanelList = this.Controls[0] as XPanderPanelList;
                  if((xpanderPanelList != null) && (xpanderPanelList.Dock == DockStyle.Fill))
                  {
                     displayRectangle = new Rectangle(
                         padding.Left,
                         this.CaptionHeight + padding.Top + Constants.BorderThickness,
                         this.ClientRectangle.Width - padding.Left - padding.Right,
                         this.ClientRectangle.Height - this.CaptionHeight - padding.Top - padding.Bottom - (2 * Constants.BorderThickness));
                  }
                  else
                  {
                     displayRectangle = new Rectangle(
                         padding.Left + Constants.BorderThickness,
                         this.CaptionHeight + padding.Top + Constants.BorderThickness,
                         this.ClientRectangle.Width - padding.Left - padding.Right - (2 * Constants.BorderThickness),
                         this.ClientRectangle.Height - this.CaptionHeight - padding.Top - padding.Bottom - (2 * Constants.BorderThickness));
                  }
               }
            }
            return displayRectangle;
         }
      }
      #endregion

      #region MethodsProtected
      /// <summary>
      /// Raises the ExpandClick event.
      /// </summary>
      /// <param name="sender">The source of the event.</param>
      /// <param name="e">An EventArgs that contains the event data.</param>
      protected override void OnExpandClick(object sender, EventArgs e)
      {
         this.Expand = !this.Expand;
         base.OnExpandClick(sender, e);
      }
      /// <summary>
      /// Raises the ExpandIconHoverState changed event.
      /// </summary>
      /// <param name="sender">The source of the event.</param>
      /// <param name="e">A HoverStateChangeEventArgs that contains the event data.</param>
      protected override void OnExpandIconHoverStateChanged(object sender, HoverStateChangeEventArgs e)
      {
         Invalidate(this.RectangleExpandIcon);
         base.OnExpandIconHoverStateChanged(sender, e);
      }
      /// <summary>
      /// Raises the CloseIconHoverStat changed event.
      /// </summary>
      /// <param name="sender">The source of the event.</param>
      /// <param name="e">A HoverStateChangeEventArgs that contains the event data.</param>
      protected override void OnCloseIconHoverStateChanged(object sender, HoverStateChangeEventArgs e)
      {
         Invalidate(this.RectangleCloseIcon);
         base.OnCloseIconHoverStateChanged(sender, e);
      }
      /// <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)
      {
         if(this.ShowTransparentBackground == true)
         {
            base.OnPaintBackground(pevent);
            this.BackColor = Color.Transparent;
         }
         else
         {
            Rectangle rectangleBounds = this.ClientRectangle;
            if(this.m_bShowCaptionbar == true)
            {
               this.BackColor = Color.Transparent;
               rectangleBounds = new Rectangle(
                   this.ClientRectangle.Left,
                   this.ClientRectangle.Top + this.CaptionHeight,
                   this.ClientRectangle.Width,
                   this.ClientRectangle.Height - this.CaptionHeight);
            }
            RenderBackgroundGradient(
                pevent.Graphics,
                rectangleBounds,
                this.PanelColors.PanelContentGradientBegin,
                this.PanelColors.PanelContentGradientEnd,
                this.LinearGradientMode);
         }
      }
      /// <summary>
      /// Raises the Paint event.
      /// </summary>
      /// <param name="e">A PaintEventArgs that contains the event data.</param>
      protected override void OnPaint(PaintEventArgs e)
      {
         PanelStyle panelStyle = this.PanelStyle;
         if(this.m_bShowCaptionbar == false)
         {
            return;
         }

         using(UseAntiAlias antiAlias = new UseAntiAlias(e.Graphics))
         {
            Graphics graphics = e.Graphics;
            using(UseClearTypeGridFit clearTypeGridFit = new UseClearTypeGridFit(graphics))
            {
               Rectangle captionRectangle = this.CaptionRectangle;
               Color colorGradientBegin = this.PanelColors.PanelCaptionGradientBegin;
               Color colorGradientEnd = this.PanelColors.PanelCaptionGradientEnd;
               Color colorGradientMiddle = this.PanelColors.PanelCaptionGradientMiddle;
               Color colorText = this.PanelColors.PanelCaptionText;
               bool bShowXPanderPanelProfessionalStyle = this.ShowXPanderPanelProfessionalStyle;
               ColorScheme colorSchema = this.ColorScheme;

               if((bShowXPanderPanelProfessionalStyle == true)
						&& (colorSchema == ColorScheme.Professional)
						&& (panelStyle != PanelStyle.Office2007))
               {
                  colorGradientBegin = this.PanelColors.XPanderPanelCaptionGradientBegin;
                  colorGradientEnd = this.PanelColors.XPanderPanelCaptionGradientEnd;
                  colorGradientMiddle = this.PanelColors.XPanderPanelCaptionGradientMiddle;
                  colorText = this.PanelColors.XPanderPanelCaptionText;
               }

               Image image = this.Image;
               RightToLeft rightToLeft = this.RightToLeft;
               Font captionFont = this.CaptionFont;
               Rectangle clientRectangle = this.ClientRectangle;
               string strText = this.Text;
               DockStyle dockStyle = this.Dock;
               bool bExpand = this.Expand;
               if(this.m_imageClosePanel == null)
               {
                  this.m_imageClosePanel = Resources.closePanel;
               }
               Color colorCloseIcon = this.PanelColors.PanelCaptionCloseIcon;
               if(colorCloseIcon == Color.Empty)
               {
                  colorCloseIcon = colorText;
               }
               bool bShowExpandIcon = this.ShowExpandIcon;
               bool bShowCloseIcon = this.ShowCloseIcon;

               switch(panelStyle)
               {
                  case BSE.Windows.Forms.PanelStyle.Default:
                  case PanelStyle.Office2007:
                  DrawStyleDefault(graphics,
              captionRectangle,
              colorGradientBegin,
              colorGradientEnd,
              colorGradientMiddle);
                  break;
               }

               DrawBorder(
                   graphics,
                   clientRectangle,
                   captionRectangle,
                   this.PanelColors.BorderColor,
                   this.PanelColors.InnerBorderColor);

               if((dockStyle == DockStyle.Fill) || (dockStyle == DockStyle.None) ||
                        ((bShowExpandIcon == false) && (bShowCloseIcon == false)))
               {
                  DrawImagesAndText(
                      graphics,
                      captionRectangle,
                      CaptionSpacing,
                      this.ImageRectangle,
                      image,
                      rightToLeft,
                      captionFont,
                      colorText,
                      strText);

                  return;
               }
               if((bShowExpandIcon == true) || (bShowCloseIcon == true))
               {
                  Image imageExpandPanel = GetExpandImage(dockStyle, bExpand);

                  DrawImagesAndText(
                      graphics,
                      dockStyle,
                      CaptionSpacing,
                      captionRectangle,
                      clientRectangle,
                      this.ImageRectangle,
                      image,
                      rightToLeft,
                      bShowCloseIcon,
                      this.m_imageClosePanel,
                      colorCloseIcon,
                      ref this.RectangleCloseIcon,
                      bShowExpandIcon,
                      bExpand,
                      imageExpandPanel,
                      colorText,
                      ref this.RectangleExpandIcon,
                      captionFont,
                      colorText,
                      this.PanelColors.PanelCollapsedCaptionText,
                      strText);

                  if(this.m_imgHoverBackground == null)
                  {
                     this.m_imgHoverBackground = GetPanelIconBackground(
                         graphics,
                         this.ImageRectangle,
                         this.PanelColors.PanelCaptionSelectedGradientBegin,
                         this.PanelColors.PanelCaptionSelectedGradientEnd);
                  }
                  if(this.m_imgHoverBackground != null)
                  {
                     Rectangle rectangleCloseIcon = this.RectangleCloseIcon;
                     if(rectangleCloseIcon != Rectangle.Empty)
                     {
                        if(this.HoverStateCloseIcon == HoverState.Hover)
                        {
                           graphics.DrawImage(this.m_imgHoverBackground, rectangleCloseIcon);
                           DrawIcon(graphics, this.m_imageClosePanel, rectangleCloseIcon, colorCloseIcon, rectangleCloseIcon.Y);
                        }
                     }
                     Rectangle rectangleExpandIcon = this.RectangleExpandIcon;
                     if(rectangleExpandIcon != Rectangle.Empty)
                     {
                        if(this.HoverStateExpandIcon == HoverState.Hover)
                        {
                           graphics.DrawImage(this.m_imgHoverBackground, rectangleExpandIcon);
                           DrawIcon(graphics, imageExpandPanel, rectangleExpandIcon, colorText, rectangleExpandIcon.Y);
                        }
                     }
                  }
               }
            }
         }
      }
      /// <summary>
      /// Raises the PanelCollapsing 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 OnPanelCollapsing(object sender, XPanderStateChangeEventArgs e)
      {
         if((this.Dock == DockStyle.Left) || (this.Dock == DockStyle.Right))
         {
            foreach(Control control in this.Controls)
            {
               control.Hide();
            }
         }

         if((this.Dock == DockStyle.Left) || (this.Dock == DockStyle.Right))
         {
            if(this.ClientRectangle.Width > this.CaptionHeight)
            {
               this.m_restoreBounds = this.ClientRectangle;
            }
            this.Width = this.CaptionHeight;
         }

         if((this.Dock == DockStyle.Top) || (this.Dock == DockStyle.Bottom))
         {
            if(this.ClientRectangle.Height > this.CaptionHeight)
            {
               this.m_restoreBounds = this.ClientRectangle;
            }
            this.Height = this.CaptionHeight;
         }

         base.OnPanelCollapsing(sender, e);
      }
      /// <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)
      {
         if((this.Dock == DockStyle.Left) || (this.Dock == DockStyle.Right))
         {
            foreach(Control control in this.Controls)
            {
               control.Show();
            }

            //When ClientRectangle.Width > CaptionHeight the panel size has changed
            //otherwise the captionclick event was executed
            if(this.ClientRectangle.Width == this.CaptionHeight)
            {
               this.Width = this.m_restoreBounds.Width;
            }
         }
         if((this.Dock == DockStyle.Top) || (this.Dock == DockStyle.Bottom))
         {
            this.Height = this.m_restoreBounds.Height;
         }

         base.OnPanelExpanding(sender, e);
      }
      /// <summary>
      /// Raises the PanelStyleChanged event
      /// </summary>
      /// <param name="sender">The source of the event.</param>
      /// <param name="e">A EventArgs that contains the event data.</param>
      protected override void OnPanelStyleChanged(object sender, PanelStyleChangeEventArgs e)
      {
         OnLayout(new LayoutEventArgs(this, null));
         base.OnPanelStyleChanged(sender, e);

      }
      /// <summary>
      /// Raises the CreateControl method.
      /// </summary>
      protected override void OnCreateControl()
      {
         this.m_restoreBounds = this.ClientRectangle;
         this.MinimumSize = new Size(this.CaptionHeight, this.CaptionHeight);
         base.OnCreateControl();
      }
      /// <summary>
      /// Raises the Resize event.
      /// </summary>
      /// <param name="e">An EventArgs that contains the event data.</param>
      protected override void OnResize(EventArgs e)
      {
         if(this.ShowExpandIcon == true)
         {
            if(this.Expand == false)
            {
               if((this.Dock == DockStyle.Left) || (this.Dock == DockStyle.Right))
               {
                  if(this.Width > this.CaptionHeight)
                  {
                     this.Expand = true;
                  }
               }
               if((this.Dock == DockStyle.Top) || (this.Dock == DockStyle.Bottom))
               {
                  if(this.Height > this.CaptionHeight)
                  {
                     this.Expand = true;
                  }
               }
            }
            else
            {
               if((this.Dock == DockStyle.Left) || (this.Dock == DockStyle.Right))
               {
                  if(this.Width == this.CaptionHeight)
                  {
                     this.Expand = false;
                  }
               }
               if((this.Dock == DockStyle.Top) || (this.Dock == DockStyle.Bottom))
               {
                  if(this.Height == this.CaptionHeight)
                  {
                     this.Expand = false;
                  }
               }
            }
         }
         base.OnResize(e);
      }
      /// <summary>
      /// Raises the <see cref="Control.VisibleChanged"/>VisibleChanged event.
      /// </summary>
      /// <param name="e">An <see cref="System.EventArgs"/> that contains the event data.</param>
      protected override void OnVisibleChanged(EventArgs e)
      {
         System.Windows.Forms.Splitter associatedSplitter = this.AssociatedSplitter;
         if(associatedSplitter != null)
         {
            associatedSplitter.Visible = this.Visible;
         }
         base.OnVisibleChanged(e);
      }
      #endregion

      #region MethodsPrivate
      /// <summary>
      /// Gets the background for an panelicon image
      /// </summary>
      /// <param name="graphics">The Graphics to draw on.</param>
      /// <param name="rectanglePanelIcon"></param>
      /// <param name="backgroundColorBegin"></param>
      /// <param name="backgroundColorEnd"></param>
      /// <returns></returns>
      private static Image GetPanelIconBackground(Graphics graphics, Rectangle rectanglePanelIcon, Color backgroundColorBegin, Color backgroundColorEnd)
      {
         Rectangle rectangle = rectanglePanelIcon;
         rectangle.X = 0;
         rectangle.Y = 0;
         Image image = new Bitmap(rectanglePanelIcon.Width, rectanglePanelIcon.Height, graphics);
         using(Graphics imageGraphics = Graphics.FromImage(image))
         {
            RenderBackgroundGradient(
                imageGraphics,
                rectangle,
                backgroundColorBegin,
                backgroundColorEnd,
                LinearGradientMode.Vertical);
         }
         return image;
      }

      private static void DrawStyleDefault(Graphics graphics,
          Rectangle captionRectangle,
          Color colorGradientBegin,
          Color colorGradientEnd,
          Color colorGradientMiddle)
      {
         RenderDoubleBackgroundGradient(
             graphics,
             captionRectangle,
             colorGradientBegin,
             colorGradientMiddle,
             colorGradientEnd,
             LinearGradientMode.Vertical,
             true);
      }

      private static void DrawBorder(
         Graphics graphics,
         Rectangle panelRectangle,
         Rectangle captionRectangle,
            Color borderColor,
         Color innerBorderColor)
      {
         using(Pen borderPen = new Pen(borderColor))
         {
            // Draws the innerborder around the captionbar
            Rectangle innerBorderRectangle = captionRectangle;
            innerBorderRectangle.Width -= Constants.BorderThickness;
            innerBorderRectangle.Offset(Constants.BorderThickness, Constants.BorderThickness);
            ControlPaint.DrawBorder(
                graphics,
                innerBorderRectangle,
                innerBorderColor,
                ButtonBorderStyle.Solid);

            // Draws the outer border around the captionbar
            ControlPaint.DrawBorder(
                graphics,
                panelRectangle,
                borderColor,
                ButtonBorderStyle.Solid);

            // Draws the line below the captionbar
            graphics.DrawLine(
                borderPen,
                captionRectangle.X,
                captionRectangle.Y + captionRectangle.Height,
                captionRectangle.Width,
                captionRectangle.Y + captionRectangle.Height);

            if(panelRectangle.Height == captionRectangle.Height)
            {
               return;
            }

            // Draws the border lines around the whole panel
            Rectangle panelBorderRectangle = panelRectangle;
            panelBorderRectangle.Y = captionRectangle.Height;
            panelBorderRectangle.Height -= captionRectangle.Height + (int) borderPen.Width;
            panelBorderRectangle.Width -= (int) borderPen.Width;
            Point[] points =
                    {
                        new Point(panelBorderRectangle.X, panelBorderRectangle.Y),
                        new Point(panelBorderRectangle.X, panelBorderRectangle.Y + panelBorderRectangle.Height),
                        new Point(panelBorderRectangle.X + panelBorderRectangle.Width ,panelBorderRectangle.Y + panelBorderRectangle.Height),
                        new Point(panelBorderRectangle.X + panelBorderRectangle.Width ,panelBorderRectangle.Y)
                    };
            graphics.DrawLines(borderPen, points);
         }
      }

      private static Image GetExpandImage(DockStyle dockStyle, bool bIsExpanded)
      {
         Image image = null;
         if((dockStyle == DockStyle.Left) && (bIsExpanded == true))
         {
            image = Resources.ChevronLeft;
         }
         else if((dockStyle == DockStyle.Left) && (bIsExpanded == false))
         {
            image = Resources.ChevronRight;
         }
         else if((dockStyle == DockStyle.Right) && (bIsExpanded == true))
         {
            image = Resources.ChevronRight;
         }
         else if((dockStyle == DockStyle.Right) && (bIsExpanded == false))
         {
            image = Resources.ChevronLeft;
         }
         else if((dockStyle == DockStyle.Top) && (bIsExpanded == true))
         {
            image = Resources.ChevronUp;
         }
         else if((dockStyle == DockStyle.Top) && (bIsExpanded == false))
         {
            image = Resources.ChevronDown;
         }
         else if((dockStyle == DockStyle.Bottom) && (bIsExpanded == true))
         {
            image = Resources.ChevronDown;
         }
         else if((dockStyle == DockStyle.Bottom) && (bIsExpanded == false))
         {
            image = Resources.ChevronUp;
         }

         return image;
      }

      #endregion 
   }

   #endregion

   #region Class PanelDesigner
   /// <summary>
   /// Extends the design mode behavior of a Panel control that supports nested controls.
   /// </summary>
   internal class PanelDesigner : System.Windows.Forms.Design.ParentControlDesigner
   {
      #region FieldsPrivate
      #endregion

      #region MethodsPublic
      /// <summary>
      /// Initializes a new instance of the PanelDesigner class.
      /// </summary>
      public PanelDesigner()
      {
      }
      /// <summary>
      /// Initializes the designer with the specified component.
      /// </summary>
      /// <param name="component"></param>
      public override void Initialize(System.ComponentModel.IComponent component)
      {
         base.Initialize(component);
      }
      /// <summary>
      /// Gets the design-time action lists supported by the component associated with the designer.
      /// </summary>
      public override DesignerActionListCollection ActionLists
      {
         get
         {
            // Create action list collection
            DesignerActionListCollection actionLists = new DesignerActionListCollection();

            // Add custom action list
            actionLists.Add(new PanelDesignerActionList(this.Component));

            // Return to the designer action service
            return actionLists;
         }
      }

      #endregion

      #region MethodsProtected
      /// <summary>
      /// Called when the control that the designer is managing has painted 
      /// its surface so the designer can paint any additional adornments on
      /// top of the control.
      /// </summary>
      /// <param name="e">A PaintEventArgs that provides data for the event.</param>
      protected override void OnPaintAdornments(PaintEventArgs e)
      {
         base.OnPaintAdornments(e);
      }

      #endregion
   }

   #endregion

   #region Class XPanderPanelListDesignerActionList
   /// <summary>
   /// Provides the class for types that define a list of items used to create a smart tag panel for the Panel.
   /// </summary>
   public class PanelDesignerActionList : DesignerActionList
   {
      #region Properties
      /// <summary>
      /// Gets or sets a value indicating whether the panels captionbar is displayed.
      /// </summary>
      public bool ShowCaptionbar
      {
         get
         {
            return this.Panel.ShowCaptionbar;
         }
         set
         {
            SetProperty("ShowCaptionbar", value);
         }
      }
      /// <summary>
      /// Gets or sets a value indicating whether the controls background is transparent.
      /// </summary>
      public bool ShowTransparentBackground
      {
         get
         {
            return this.Panel.ShowTransparentBackground;
         }
         set
         {
            SetProperty("ShowTransparentBackground", value);
         }
      }
      /// <summary>
      /// Gets or sets a value indicating whether the controls caption professional colorscheme is the same then the XPanderPanels
      /// </summary>
      public bool ShowXPanderPanelProfessionalStyle
      {
         get
         {
            return this.Panel.ShowXPanderPanelProfessionalStyle;
         }
         set
         {
            SetProperty("ShowXPanderPanelProfessionalStyle", value);
         }
      }
      /// <summary>
      /// Gets or sets a value indicating whether the expand icon of the panel is visible
      /// </summary>
      public bool ShowExpandIcon
      {
         get
         {
            return this.Panel.ShowExpandIcon;
         }
         set
         {
            SetProperty("ShowExpandIcon", value);
         }
      }
      /// <summary>
      /// Gets or sets a value indicating whether the close icon is visible
      /// </summary>
      public bool ShowCloseIcon
      {
         get
         {
            return this.Panel.ShowCloseIcon;
         }
         set
         {
            SetProperty("ShowCloseIcon", value);
         }
      }
      /// <summary>
      /// Gets or sets the style of the panel.
      /// </summary>
      public PanelStyle PanelStyle
      {
         get
         {
            return this.Panel.PanelStyle;
         }
         set
         {
            SetProperty("PanelStyle", value);
         }
      }
      /// <summary>
      /// Gets or sets the color schema which is used for the panel.
      /// </summary>
      public ColorScheme ColorScheme
      {
         get
         {
            return this.Panel.ColorScheme;
         }
         set
         {
            SetProperty("ColorScheme", value);
         }
      }
      #endregion

      #region MethodsPublic
      /// <summary>
      /// Initializes a new instance of the PanelDesignerActionList class.
      /// </summary>
      /// <param name="component">A component related to the DesignerActionList.</param>
      public PanelDesignerActionList(System.ComponentModel.IComponent component)
         : base(component)
      {
         // Automatically display smart tag panel when
         // design-time component is dropped onto the
         // Windows Forms Designer
         base.AutoShow = true;
      }
      /// <summary>
      /// Returns the collection of DesignerActionItem objects contained in the list.
      /// </summary>
      /// <returns> A DesignerActionItem array that contains the items in this list.</returns>
      public override DesignerActionItemCollection GetSortedActionItems()
      {
         // Create list to store designer action items
         DesignerActionItemCollection actionItems = new DesignerActionItemCollection();

         actionItems.Add(
           new DesignerActionMethodItem(
             this,
             "ToggleDockStyle",
             GetDockStyleText(),
             "Design",
             "Dock or undock this control in it's parent container.",
             true));

         actionItems.Add(
            new DesignerActionPropertyItem(
            "ShowTransparentBackground",
            "Show transparent backcolor",
            GetCategory(this.Panel, "ShowTransparentBackground")));

         actionItems.Add(
            new DesignerActionPropertyItem(
            "ShowXPanderPanelProfessionalStyle",
            "Show the XPanderPanels professional colorscheme",
            GetCategory(this.Panel, "ShowXPanderPanelProfessionalStyle")));

         actionItems.Add(
             new DesignerActionPropertyItem(
             "ShowCaptionbar",
             "Show the captionbar on top of the panel",
             GetCategory(this.Panel, "ShowCaptionbar")));

         actionItems.Add(
         new DesignerActionPropertyItem(
         "ShowExpandIcon",
         "Show the expand panel icon (not at DockStyle.None or DockStyle.Fill)",
         GetCategory(this.Panel, "ShowExpandIcon")));

         actionItems.Add(
             new DesignerActionPropertyItem(
             "ShowCloseIcon",
         "Show the close panel icon (not at DockStyle.None or DockStyle.Fill)",
             GetCategory(this.Panel, "ShowCloseIcon")));

         actionItems.Add(
            new DesignerActionPropertyItem(
            "PanelStyle",
            "Select PanelStyle",
            GetCategory(this.Panel, "PanelStyle")));

         actionItems.Add(
            new DesignerActionPropertyItem(
            "ColorScheme",
            "Select ColorScheme",
            GetCategory(this.Panel, "ColorScheme")));

         return actionItems;
      }
      /// <summary>
      /// Dock/Undock designer action method implementation
      /// </summary>
      public void ToggleDockStyle()
      {

         // Toggle ClockControl's Dock property
         if(this.Panel.Dock != DockStyle.Fill)
         {
            SetProperty("Dock", DockStyle.Fill);
         }
         else
         {
            SetProperty("Dock", DockStyle.None);
         }
      }

      #endregion

      #region MethodsPrivate

      // Helper method that returns an appropriate
      // display name for the Dock/Undock property,
      // based on the ClockControl's current Dock 
      // property value
      private string GetDockStyleText()
      {
         if(this.Panel.Dock == DockStyle.Fill)
         {
            return "Undock in parent container";
         }
         else
         {
            return "Dock in parent container";
         }
      }

      private Panel Panel
      {
         get
         {
            return (Panel) this.Component;
         }
      }

      // Helper method to safely set a component’s property
      private void SetProperty(string propertyName, object value)
      {
         // Get property
         System.ComponentModel.PropertyDescriptor property
				= System.ComponentModel.TypeDescriptor.GetProperties(this.Panel)[propertyName];
         // Set property value
         property.SetValue(this.Panel, value);
      }

      // Helper method to return the Category string from a
      // CategoryAttribute assigned to a property exposed by 
      //the specified object
      private static string GetCategory(object source, string propertyName)
      {
         System.Reflection.PropertyInfo property = source.GetType().GetProperty(propertyName);
         CategoryAttribute attribute = (CategoryAttribute) property.GetCustomAttributes(typeof(CategoryAttribute), false)[0];
         if(attribute == null)
            return null;
         return attribute.Category;
      }

      #endregion
   }

   #endregion
}