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

resize, winforms

Solution

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:

- AutoLayout By Examples

- WinForms AutoLayout Basics: TableLayoutPanel

- Video Training on TableLayoutPanel

Problem

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?

Original source