C# – Stuff in Windows Form Move When Maximized – C#


It's been a while since I've programmed a GUI program, so this may end up being super simple, but I can't find the solution anywhere online.

Basically my problem is that when I maximize my program, all the things inside of the window (buttons, textboxes, etc.) stay in the same position in the window, which results in a large blank area near the bottom and right side.

Is there a way of making the the elements in the program to stretch to scale?

Best Solution

You want to check and properly set the Anchor and Dock properties on each control in the Form. The Anchor property on a control tells which sides of the form (top, bottom, left, right) the control is 'anchored' to. When the form is resized, the distance between the control and its anchors will stay the same. This lets you make a control stay in the bottom right corner for example.

The Dock property instructs the control to fill the entire parent form or to fill one side of it (again top, bottom, left or right).