C# Winforms: GroupBox not resizing

scryptKiddy picture scryptKiddy · Aug 23, 2013 · Viewed 12.5k times · Source

I have two GroupBoxes on the left side of one of my TabControls, call them GroupBox A (top left), and GroupBox B (bottom left). The GroupBoxes do not resize like I would hope.

Example: When I resize the main form that has the TabControls with my mouse, or maximize it, or move it to a screen with lower resolution, GroupBox B keeps its width / height. This causes GroupBox B to draw over GroupBox A, kind of like a 'always on top' effect.

Desired: Would like both GroupBoxes to resize according to one another / proporitionally and fit the area they are given.

Ideas?

Answer

jmstoker picture jmstoker · Aug 24, 2013

A tableLayoutPanel can help with this.

  1. Add a tableLayoutPanel and size it to fit your needs.
  2. Anchor the table to Top, Bottom, Left, and Right
  3. Put GroupBoxA into the upper left cell of the table
  4. Put GroupBoxB into the lower right cell of the table
  5. For both GroupBox size them accordingly and anchor them to all 4 sides.
  6. Now they will grow and shrink proportionately with the app.

Additionally you can add more of your controls to the table. If you need a control to span multiple rows or columns use the RowSpan/ColumnSpan property.