Customizing Windows Forms In C#

  
 
    
 
     
 
 


Introduction
 
I wanted to create Custom windows forms in C#. Before working on this code, i started to find any code that could help me to create custom windows forms in C# on internet. but unfortunately i couldn't find any simple and useful also looks good form code. I found some code but they all are complicated. I also found some codes that are simple but not useful. When i started working on solving this problem, i thought to use Custom Panel/Panel as a border of a Frame for change the size of Form such as Width, Height etc and use Custom Buttons as a Control Box of a Frame.
Use Custom Panel as a Top layered Title border of a frame and use label to display text of a frame.
To display icon on a frame we will set background image to added panel.
Applying Mouse Events to panels and change properties of Form.
 
And it works perfectly.

You require Visual Studio Professional 2013 or higher version and .NET framework 4.5 or higher.


     


Perform following all Steps correctly to create custom windows forms.

We can also create extended advanced forms using only panels.(see above images,image 1 & 2)

Download the source code to view code for those forms.

See above image for better understanding of resizing our customized form and BlackForm.cs in file.

In this article we will create Blue colored resizable custom windows form, change colors of panels and buttons as you wish.
You can use Custom Controls to design a form.
Dont have Custom Controls ?

 
 
 
Start
 

Step 1 : Start Visual Studio and Create new Windows Forms Application project in C#.
                I created CustomWindowsForm project.
                Download the source code and view the code for BlueForm.cs.
                Now set following Properties to created Form (Form1).
 

 ControlBox false
 BackColor 30,60,150
 FormBorderStyle None
 Size 684,461
 
 
              To Add icon you can add again a panel and set background image to it used as a window icon. 
 
 
Step 2 : Now, Go to Project -> Add Class
                Enter Name ButtonZ and click Add.
                Now Copy and Paste following ButtonZ code into your created class ButtonZ code.
                this button code is for create our Close & Minimize buttons of the form. 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using System.Drawing;  
  5. using System.Data;  
  6. using System.Windows.Forms;  
  7. namespace CustomWindowsForm  
  8. {  
  9.     public class ButtonZ : System.Windows.Forms.Button  
  10.     {  
  11.         Color clr1;  
  12.         private Color color = Color.Teal;  
  13.         private Color m_hovercolor = Color.FromArgb(0, 0, 140);  
  14.         private Color clickcolor = Color.FromArgb(160, 180, 200);  
  15.         private int textX = 6;  
  16.         private int textY = -20;  
  17.         private String text = "_";  
  18.   
  19.         public String DisplayText  
  20.         {  
  21.             get { return text; }  
  22.             set { text = value; Invalidate(); }  
  23.         }  
  24.         public Color BZBackColor  
  25.         {  
  26.             get { return color; }  
  27.             set { color = value; Invalidate(); }  
  28.         }  
  29.   
  30.         public Color MouseHoverColor  
  31.         {  
  32.             get { return m_hovercolor; }  
  33.             set { m_hovercolor = value; Invalidate(); }  
  34.         }  
  35.   
  36.         public Color MouseClickColor1  
  37.         {  
  38.             get { return clickcolor; }  
  39.             set { clickcolor = value; Invalidate(); }  
  40.         }  
  41.   
  42.   
  43.         public int TextLocation_X  
  44.         {  
  45.             get { return textX; }  
  46.             set { textX = value; Invalidate(); }  
  47.         }  
  48.         public int TextLocation_Y  
  49.         {  
  50.             get { return textY; }  
  51.             set { textY = value; Invalidate(); }  
  52.         }  
  53.         public ButtonZ()  
  54.         {  
  55.             this.Size = new System.Drawing.Size(31, 24);  
  56.             this.ForeColor = Color.White;  
  57.             this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;  
  58.             this.Font = new System.Drawing.Font("Microsoft YaHei UI", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));  
  59.             this.Text = "_";  
  60.             text = this.Text;  
  61.         }  
  62.         //method mouse enter  
  63.         protected override void OnMouseEnter(EventArgs e)  
  64.         {  
  65.             base.OnMouseEnter(e);  
  66.             clr1 = color;  
  67.             color = m_hovercolor;  
  68.         }  
  69.         //method mouse leave  
  70.         protected override void OnMouseLeave(EventArgs e)  
  71.         {  
  72.             base.OnMouseLeave(e);  
  73.             color = clr1;  
  74.         }  
  75.   
  76.         protected override void OnMouseDown(MouseEventArgs mevent)  
  77.         {  
  78.             base.OnMouseDown(mevent);  
  79.             color = clickcolor;  
  80.         }  
  81.   
  82.         protected override void OnMouseUp(MouseEventArgs mevent)  
  83.         {  
  84.             base.OnMouseUp(mevent);  
  85.             color = clr1;  
  86.         }  
  87.   
  88.   
  89.         protected override void OnPaint(PaintEventArgs pe)  
  90.         {  
  91.             base.OnPaint(pe);  
  92.             text = this.Text;  
  93.             if (textX == 100 && textY == 25)  
  94.             {  
  95.                 textX = ((this.Width) / 3) + 10;  
  96.                 textY = (this.Height / 2) - 1;  
  97.             }  
  98.   
  99.             Point p = new Point(textX, textY);  
  100.             pe.Graphics.FillRectangle(new SolidBrush(color), ClientRectangle);  
  101.             pe.Graphics.DrawString(text, this.Font, new SolidBrush(this.ForeColor), p);  
  102.         }  
  103.   
  104.     }  
  105. }  
 
 
Step 3 : Now, Go to Project -> Add Class
                Enter Name MinMaxButton and click Add.
                Now Copy and Paste following MinMaxButton code into your created class MinMaxButton code.
               this code is for to create our maximize & restore down button when form is maximized. 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using System.Drawing;  
  5. using System.Data;  
  6. using System.Windows.Forms;  
  7. namespace CustomWindowsForm  
  8. {  
  9.     public class MinMaxButton : System.Windows.Forms.Button  
  10.     {  
  11.         Color clr1;  
  12.         private Color color = Color.Gray;  
  13.         private Color m_hovercolor = Color.FromArgb(180, 200, 240);  
  14.         private Color clickcolor = Color.FromArgb(160, 180, 200);  
  15.         private int textX = 6;  
  16.         private int textY = -20;  
  17.         private String text = "_";  
  18.   
  19.         public enum CustomFormState  
  20.         {  
  21.             Normal,  
  22.             Maximize  
  23.         }  
  24.   
  25.         CustomFormState _customFormState;  
  26.   
  27.         public CustomFormState CFormState  
  28.         {  
  29.             get { return _customFormState; }  
  30.             set { _customFormState = value; Invalidate(); }  
  31.         }  
  32.   
  33.   
  34.         public String DisplayText  
  35.         {  
  36.             get { return text; }  
  37.             set { text = value; Invalidate(); }  
  38.         }  
  39.         public Color BZBackColor  
  40.         {  
  41.             get { return color; }  
  42.             set { color = value; Invalidate(); }  
  43.         }  
  44.   
  45.         public Color MouseHoverColor  
  46.         {  
  47.             get { return m_hovercolor; }  
  48.             set { m_hovercolor = value; Invalidate(); }  
  49.         }  
  50.   
  51.         public Color MouseClickColor1  
  52.         {  
  53.             get { return clickcolor; }  
  54.             set { clickcolor = value; Invalidate(); }  
  55.         }  
  56.   
  57.   
  58.         public int TextLocation_X  
  59.         {  
  60.             get { return textX; }  
  61.             set { textX = value; Invalidate(); }  
  62.         }  
  63.         public int TextLocation_Y  
  64.         {  
  65.             get { return textY; }  
  66.             set { textY = value; Invalidate(); }  
  67.         }  
  68.   
  69.         public MinMaxButton()  
  70.         {  
  71.             this.Size = new System.Drawing.Size(31, 24);  
  72.             this.ForeColor = Color.White;  
  73.             this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;  
  74.             this.Text = "_";  
  75.             text = this.Text;  
  76.         }  
  77.   
  78.         //method mouse enter  
  79.         protected override void OnMouseEnter(EventArgs e)  
  80.         {  
  81.             base.OnMouseEnter(e);  
  82.             clr1 = color;  
  83.             color = m_hovercolor;  
  84.         }  
  85.         //method mouse leave  
  86.         protected override void OnMouseLeave(EventArgs e)  
  87.         {  
  88.             base.OnMouseLeave(e);  
  89.             color = clr1;  
  90.         }  
  91.   
  92.         protected override void OnMouseDown(MouseEventArgs mevent)  
  93.         {  
  94.             base.OnMouseDown(mevent);  
  95.             color = clickcolor;  
  96.         }  
  97.   
  98.         protected override void OnMouseUp(MouseEventArgs mevent)  
  99.         {  
  100.             base.OnMouseUp(mevent);  
  101.             color = clr1;  
  102.         }  
  103.   
  104.   
  105.         protected override void OnPaint(PaintEventArgs pe)  
  106.         {  
  107.             base.OnPaint(pe);  
  108.   
  109.             switch (_customFormState)  
  110.             {  
  111.                 case CustomFormState.Normal:  
  112.                     pe.Graphics.FillRectangle(new SolidBrush(color), ClientRectangle);  
  113.   
  114.                     //draw and fill thw rectangles of maximized window       
  115.                     for (int i = 0; i < 2; i++)  
  116.                     {  
  117.                         pe.Graphics.DrawRectangle(new Pen(this.ForeColor), textX + i + 1, textY, 10, 10);  
  118.                         pe.Graphics.FillRectangle(new SolidBrush(this.ForeColor), textX + 1, textY - 1, 12, 4);  
  119.                     }  
  120.                     break;  
  121.   
  122.                 case CustomFormState.Maximize:  
  123.                     pe.Graphics.FillRectangle(new SolidBrush(color), ClientRectangle);  
  124.   
  125.                     //draw and fill thw rectangles of maximized window       
  126.                     for (int i = 0; i < 2; i++)  
  127.                     {  
  128.                         pe.Graphics.DrawRectangle(new Pen(this.ForeColor), textX + 5, textY, 8, 8);  
  129.                         pe.Graphics.FillRectangle(new SolidBrush(this.ForeColor), textX + 5, textY - 1, 9, 4);  
  130.   
  131.                         pe.Graphics.DrawRectangle(new Pen(this.ForeColor), textX + 2, textY + 5, 8, 8);  
  132.                         pe.Graphics.FillRectangle(new SolidBrush(this.ForeColor), textX + 2, textY + 4, 9, 4);  
  133.   
  134.                     }  
  135.                     break;  
  136.             }  
  137.   
  138.         }  
  139.   
  140.   
  141.     }  
  142. }  
 

Step 4 : Run your Form and exit it.For to create library of above code for darg & drop components.

 

Step 5 : Drag & Drop Panel onto your Form (TopBorderPanel)
               Set following Properties to dropped panel.

 Name TopBorderPanel
 BackColor 10,20,50
 Cursor SizeNS
 Dock Top
 Size 684,2
 
 
 
Step 6 : Drag & Drop Panel onto your Form (TopPanel)
               Set following Properties to dropped panel.  
 
 Name TopPanel
 BackColor 20,40,80
 Cursor Default
 Dock Top
 Size 680,35
 
 

Step 7 : Drag & Drop Panel onto your Form (LeftPanel)
                Set following Properties to dropped panel.

 Name LeftPanel
 BackColor10,20,50
 CursorSizeWE
 DockLeft 
 Size2,459 
 

 

Step 8Drag & Drop Panel onto your Form (RightPanel)
               Set following Properties to dropped panel.

 Name RightPanel
 BackColor10,20,50
 CursorSizeWE
 DockRight 
 Size2,459 
 

 
Step 9 : Drag & Drop Panel onto your Form (BottomPanel)
                Set following Properties to dropped panel.

 

 NameBottomPanel
 BackColor10,20,50
 CursorSizeNS
 DockBottom 
 Size680,2 
 

 

Step 10 : Drag & Drop ToolTip onto your form
 
 

Step 11 : Drag & Drop ButtonZ onto TopPanel (_CloseButton)
                  Set following Properties to dropped button.

 Name _CloseButton
 AnchorTop,Right
 BZBackColor20,40,80
 DisplayText
 FontMicrosoft YaHei UI, 11.25pt, style=Bold 
 ForeColor White
 Location 639,3
 MouseClickColor1 150,0,0
 MouseHoverColor40,80,180 
 Size35,35 
 Text
 TextLocation_X10 
 TextLocation_Y 4
 ToolTip on toolTip1Close   
 
Adjust button location as you wish.
 
 
Step 12 : Drag & Drop ButtonZ onto TopPanel (_MinButton)
               Set following Properties to dropped button.
 
Name _MinButton
AnchorTop,Right
BZBackColor20,40,80
DisplayText_
FontMicrosoft YaHei UI, 18pt, style=Bold
ForeColor White
Location569,3
MouseClickColor1 10,20,60
MouseHoverColor40,80,180
Size35,35
Text_
TextLocation_X8
TextLocation_Y-14
ToolTip on toolTip1Minimize
 

 
Step 13 : Drag & Drop MinMaxButton onto TopPanel (_MaxButton)
                  Set following Properties to dropped button.
 
 Name _MaxButton
 AnchorTop,Right
 BZBackColor20,40,80
 CFormStateNormal 
 ForeColorWhite 
 Location604,3 
 MouseClickColor110,20,60 
 MouseHoverColor40,80,180 
 Size35,25 
 TextLocation_X11 
 TextLocation_Y
 ToolTip on toolTip1Maximize
 
 
For text of our custom for, you can add Label and use it as a text of a form.
 
 
Step 14 : Add following variables to code of Form1 globally
  1. bool isTopPanelDragged = false;  
  2. bool isLeftPanelDragged = false;  
  3. bool isRightPanelDragged = false;  
  4. bool isBottomPanelDragged = false;  
  5. bool isTopBorderPanelDragged = false;  
  6. bool isWindowMaximized = false;  
  7. Point offset;  
  8. Size _normalWindowSize;  
  9. Point _normalWindowLocation = Point.Empty;  
 

isTopPanelDragged is to check that mouse down event triggered by top panel or not.
Same for Left,Right,Bottom,TopBorder panels.
isWindowMaximized is to check whether _MaxButton click event occured or not.
offset is temporary variable to store location of our form.
_normalWindowSize is to hold normal window size after clicking on _MaxButton for go to normal window size
Same as for _normalWindowLocation only just to store form location.

 

Step 15 : Now add Events to Panels and Buttons in Events Box
                  MouseDown,MouseMove & MouseUp events to Panels.

TopBorderPanel : 

  • TopBorderPanel_MouseDown 
  • TopBorderPanel_MouseMove 
  • TopBorderPanel_MouseUp

TopPanel :

  • TopPanel_MouseDown 
  • TopPanel_MouseMove 
  • TopPanel_MouseUp 

LeftPanel :
  • LeftPanel_MouseDown 
  • LeftPanel_MouseMove 
  • LeftPanel_MouseUp 

RightPanel :
  • RightPanel_MouseDown 
  • RightPanel_MouseMove 
  • RightPanel_MouseUp 

BottomPanel :
  • BottomPanel_MouseDown 
  • BottomPanel_MouseMove 
  • BottomPanel_MouseUp 

_MinButton :
  • _MinButton_Click 

_MaxButton :
  • _MaxButton_Click 

_CloseButton :
  • _CloseButton_Click 


Step 16 : Once you added all above events to all components then replace your Form1.cs code with following code. Just make changes in classes, namespaces etc. Download the source code for view simple blue colored custom form.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9. using System.Windows.Forms;  
  10.   
  11. namespace CustomWindowsForm  
  12. {  
  13.     public partial class Form1 : Form  
  14.     {  
  15.         public Form1()  
  16.         {  
  17.             InitializeComponent();  
  18.         }  
  19.   
  20.   
  21.         bool isTopPanelDragged = false;  
  22.         bool isLeftPanelDragged = false;  
  23.         bool isRightPanelDragged = false;  
  24.         bool isBottomPanelDragged = false;  
  25.         bool isTopBorderPanelDragged = false;  
  26.         bool isWindowMaximized = false;  
  27.         Point offset;  
  28.         Size _normalWindowSize;  
  29.         Point _normalWindowLocation = Point.Empty;  
  30.   
  31.   
  32.         private void TopBorderPanel_MouseDown(object sender, MouseEventArgs e)  
  33.         {  
  34.             if (e.Button == MouseButtons.Left)  
  35.             {  
  36.                 isTopBorderPanelDragged = true;  
  37.             }  
  38.             else  
  39.             {  
  40.                 isTopBorderPanelDragged = false;  
  41.             }  
  42.         }  
  43.   
  44.         private void TopBorderPanel_MouseMove(object sender, MouseEventArgs e)  
  45.         {  
  46.             if (e.Y < this.Location.Y)  
  47.             {  
  48.                 if (isTopBorderPanelDragged)  
  49.                 {  
  50.                     if (this.Height < 50)  
  51.                     {  
  52.                         this.Height = 50;  
  53.                         isTopBorderPanelDragged = false;  
  54.                     }  
  55.                     else  
  56.                     {  
  57.                         this.Location = new Point(this.Location.X, this.Location.Y + e.Y);  
  58.                         this.Height = this.Height - e.Y;  
  59.                     }  
  60.                 }  
  61.             }  
  62.         }  
  63.   
  64.         private void TopBorderPanel_MouseUp(object sender, MouseEventArgs e)  
  65.         {  
  66.             isTopBorderPanelDragged = false;  
  67.         }  
  68.   
  69.   
  70.   
  71.   
  72.         private void TopPanel_MouseDown(object sender, MouseEventArgs e)  
  73.         {  
  74.             if (e.Button == MouseButtons.Left)  
  75.             {  
  76.                 isTopPanelDragged = true;  
  77.                 Point pointStartPosition = this.PointToScreen(new Point(e.X, e.Y));  
  78.                 offset = new Point();  
  79.                 offset.X = this.Location.X - pointStartPosition.X;  
  80.                 offset.Y = this.Location.Y - pointStartPosition.Y;  
  81.             }  
  82.             else  
  83.             {  
  84.                 isTopPanelDragged = false;  
  85.             }  
  86.             if (e.Clicks == 2)  
  87.             {  
  88.                 isTopPanelDragged = false;  
  89.                 _MaxButton_Click(sender, e);  
  90.             }  
  91.         }  
  92.   
  93.         private void TopPanel_MouseMove(object sender, MouseEventArgs e)  
  94.         {  
  95.             if (isTopPanelDragged)  
  96.             {  
  97.                 Point newPoint = TopPanel.PointToScreen(new Point(e.X, e.Y));  
  98.                 newPoint.Offset(offset);  
  99.                 this.Location = newPoint;  
  100.   
  101.                 if (this.Location.X > 2 || this.Location.Y > 2)  
  102.                 {  
  103.                     if (this.WindowState == FormWindowState.Maximized)  
  104.                     {  
  105.                         this.Location = _normalWindowLocation;  
  106.                         this.Size = _normalWindowSize;  
  107.                         toolTip1.SetToolTip(_MaxButton, "Maximize");  
  108.                         _MaxButton.CFormState = MinMaxButton.CustomFormState.Normal;  
  109.                         isWindowMaximized = false;  
  110.                     }  
  111.                 }  
  112.             }  
  113.         }  
  114.   
  115.         private void TopPanel_MouseUp(object sender, MouseEventArgs e)  
  116.         {  
  117.             isTopPanelDragged = false;  
  118.             if (this.Location.Y <= 5)  
  119.             {  
  120.                 if (!isWindowMaximized)  
  121.                 {  
  122.                     _normalWindowSize = this.Size;  
  123.                     _normalWindowLocation = this.Location;  
  124.   
  125.                     Rectangle rect = Screen.PrimaryScreen.WorkingArea;  
  126.                     this.Location = new Point(0, 0);  
  127.                     this.Size = new System.Drawing.Size(rect.Width, rect.Height);  
  128.                     toolTip1.SetToolTip(_MaxButton, "Restore Down");  
  129.                     _MaxButton.CFormState = MinMaxButton.CustomFormState.Maximize;  
  130.                     isWindowMaximized = true;  
  131.                 }  
  132.             }  
  133.         }  
  134.   
  135.   
  136.   
  137.         private void LeftPanel_MouseDown(object sender, MouseEventArgs e)  
  138.         {  
  139.             if (this.Location.X <= 0 || e.X < 0)  
  140.             {  
  141.                 isLeftPanelDragged = false;  
  142.                 this.Location = new Point(10, this.Location.Y);  
  143.             }  
  144.             else  
  145.             {  
  146.                 if (e.Button == MouseButtons.Left)  
  147.                 {  
  148.                     isLeftPanelDragged = true;  
  149.                 }  
  150.                 else  
  151.                 {  
  152.                     isLeftPanelDragged = false;  
  153.                 }  
  154.             }  
  155.         }  
  156.   
  157.         private void LeftPanel_MouseMove(object sender, MouseEventArgs e)  
  158.         {  
  159.             if (e.X < this.Location.X)  
  160.             {  
  161.                 if (isLeftPanelDragged)  
  162.                 {  
  163.                     if (this.Width < 100)  
  164.                     {  
  165.                         this.Width = 100;  
  166.                         isLeftPanelDragged = false;  
  167.                     }  
  168.                     else  
  169.                     {  
  170.                         this.Location = new Point(this.Location.X + e.X, this.Location.Y);  
  171.                         this.Width = this.Width - e.X;  
  172.                     }  
  173.                 }  
  174.             }  
  175.         }  
  176.   
  177.         private void LeftPanel_MouseUp(object sender, MouseEventArgs e)  
  178.         {  
  179.             isLeftPanelDragged = false;  
  180.         }  
  181.   
  182.   
  183.   
  184.         private void RightPanel_MouseDown(object sender, MouseEventArgs e)  
  185.         {  
  186.             if (e.Button == MouseButtons.Left)  
  187.             {  
  188.                 isRightPanelDragged = true;  
  189.             }  
  190.             else  
  191.             {  
  192.                 isRightPanelDragged = false;  
  193.             }  
  194.         }  
  195.   
  196.         private void RightPanel_MouseMove(object sender, MouseEventArgs e)  
  197.         {  
  198.             if (isRightPanelDragged)  
  199.             {  
  200.                 if (this.Width < 100)  
  201.                 {  
  202.                     this.Width = 100;  
  203.                     isRightPanelDragged = false;  
  204.                 }  
  205.                 else  
  206.                 {  
  207.                     this.Width = this.Width + e.X;  
  208.                 }  
  209.             }  
  210.         }  
  211.   
  212.         private void RightPanel_MouseUp(object sender, MouseEventArgs e)  
  213.         {  
  214.             isRightPanelDragged = false;  
  215.         }  
  216.   
  217.   
  218.   
  219.         private void BottomPanel_MouseDown(object sender, MouseEventArgs e)  
  220.         {  
  221.             if (e.Button == MouseButtons.Left)  
  222.             {  
  223.                 isBottomPanelDragged = true;  
  224.             }  
  225.             else  
  226.             {  
  227.                 isBottomPanelDragged = false;  
  228.             }  
  229.         }  
  230.   
  231.         private void BottomPanel_MouseMove(object sender, MouseEventArgs e)  
  232.         {  
  233.             if (isBottomPanelDragged)  
  234.             {  
  235.                 if (this.Height < 50)  
  236.                 {  
  237.                     this.Height = 50;  
  238.                     isBottomPanelDragged = false;  
  239.                 }  
  240.                 else  
  241.                 {  
  242.                     this.Height = this.Height + e.Y;  
  243.                 }  
  244.             }  
  245.         }  
  246.   
  247.         private void BottomPanel_MouseUp(object sender, MouseEventArgs e)  
  248.         {  
  249.             isBottomPanelDragged = false;  
  250.         }  
  251.   
  252.   
  253.   
  254.   
  255.         private void _CloseButton_Click(object sender, EventArgs e)  
  256.         {  
  257.             this.Close();  
  258.         }  
  259.   
  260.         private void _MaxButton_Click(object sender, EventArgs e)  
  261.         {  
  262.             if (isWindowMaximized)  
  263.             {  
  264.                 this.Location = _normalWindowLocation;  
  265.                 this.Size = _normalWindowSize;  
  266.                 toolTip1.SetToolTip(_MaxButton, "Maximize");  
  267.                 _MaxButton.CFormState = MinMaxButton.CustomFormState.Normal;  
  268.                 isWindowMaximized = false;  
  269.             }  
  270.             else  
  271.             {  
  272.                 _normalWindowSize = this.Size;  
  273.                 _normalWindowLocation = this.Location;  
  274.   
  275.                 Rectangle rect = Screen.PrimaryScreen.WorkingArea;  
  276.                 this.Location = new Point(0, 0);  
  277.                 this.Size = new System.Drawing.Size(rect.Width, rect.Height);  
  278.                 toolTip1.SetToolTip(_MaxButton, "Restore Down");  
  279.                 _MaxButton.CFormState = MinMaxButton.CustomFormState.Maximize;  
  280.                 isWindowMaximized = true;  
  281.             }  
  282.         }  
  283.   
  284.         private void _MinButton_Click(object sender, EventArgs e)  
  285.         {  
  286.             this.WindowState = FormWindowState.Minimized;  
  287.         }  
  288.     }  
  289. }  
 
 Here is the output of above all procedures
 
   
 
Well we have created a custom forms,so you directly cannot add some controls to a form like MenuStrip, SplitContainer etc. To add these controls first you need to add panels and add them onto that panel so that our customize form will not be changed. 
 
 
 
 

Up Next
    Ebook Download
    View all
    Learn
    View all