How do I resize my panels when resizing the main form in a winforms application?

18,840

Solution 1

If the user of my winforms application resizes the main form, I want the 2 panels to stretch out also, along with the child controls.

You're the ideal use case for TableLayoutPanel (MSDN). If you were only scaling the panels, Dock and Anchor would be appropriate. But since you want your controls to scale well, you're pretty much in an AutoLayout world, and likely the TableLayoutPanel. (I'm a huge fan of this, by the way, although overuse can have a negative performance impact on laying out your controls.)

Some helpful links on using it to configure your layout to scale:

Solution 2

Play around with the Dock and Anchor properties of your panels.

Solution 3

You can use the TableLayoutPanel and set column width at x% each this way you will have the screen split in 2. The TableLayoutPanel must be Dock to fill all the form or Anchor.

The TableLayoutPanel can contain other panel. OR you can use simply your panel and use Anchor (click the panel and go in the Properties panel of VS).

Share:
18,840
Admin
Author by

Admin

Updated on June 18, 2022

Comments

  • Admin
    Admin almost 2 years

    If the user of my winforms application resizes the main form, I want the 2 panels to stretch out also, along with the child controls.

    How can I achieve this?

  • MusiGenesis
    MusiGenesis over 15 years
    Argh. I write software for Windows Mobile devices, and once again I just had the experience of learning about a cool .NET feature that isn't in the Compact Framework.
  • John Rudy
    John Rudy almost 15 years
    For future visitors of this answer: I just noticed a link to my blog in this answer, and have now removed it, as I shut the blog down many months ago. I apologize for the inconvenience.