George Shepherd's Windows Forms FAQ
Questions and answers in this FAQ have been collected from newsgroup posts, various mailing lists and the employees of Syncfusion.

6. Windows Forms Docking

WinForms FAQ Home
   6.1 How can I make a control occupy all the client area of a form?
   6.2 How can I make my control automatically grow when the parent form is sized?
   6.3 What is the difference between a form's Anchor property and a form's Dock property?



6.1 How can I make a control occupy all the client area of a form?


private void Form1_Load(object sender, System.EventArgs e)
{
     Bitmap newBmp = new Bitmap(100, 100);
     Graphics g = Graphics.FromImage(newBmp);
     g.FillRectangle(new SolidBrush(Color.Red), 0, 0, 33, 100);
     g.FillRectangle(new SolidBrush(Color.White), 34, 0, 33, 100);
     g.FillRectangle(new SolidBrush(Color.Blue), 68, 0, 33, 100);
     pictureBox1.Image = newBmp; //pictureBox1 was dropped on the form
}


6.2 How can I make my control automatically grow when the parent form is sized?


Change the control's Anchor property so that it is anchored on all 4 sides.



Please note that you can only have 1 control per form anchored in this manner (all 4 sides). And other controls on the form should be anchored by their sides that are not adjacent to special control anchored on all 4 sides.


6.3 What is the difference between a form's Anchor property and a form's Dock property?


G. G. Arun Ganesh discusses these properties in Working with Anchoring and Docking Properties in C# on C# Corner.

© 2001-2010 Copyright Syncfusion Inc. All rights reserved.  |  Privacy Policy  |  Contact  |  Sitemap