Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to make Windows Forms forms resizable

I am working on a largish C# project with a lot of Windows Forms forms that, even though you can resize the form, the elements in the form don't scale.

How can I make the form elements (such as the datagridview, text area's, etc.) scale when the user changes the size of the form?

Nearly all the forms subclass from one specific form, so if there's something I can do in the base class, that'd be great.

like image 617
Malfist Avatar asked Jun 25 '10 15:06

Malfist


People also ask

How do I make my windows form resizable?

By dragging either the right edge, bottom edge, or the corner, you can resize the form.

How do I fix the size of a Windows Form?

Right click on your form and go to properties. Then go to Layout options,see there are a property named Size. Change it as your need as width and length wise. Also see a property named StartPosition just after the Size property.


1 Answers

You should set the Anchor and Dock properties on the controls in the forms.

The Anchor property controls which edges of a control are "bound" or "tied" to the corresponding edges of its form.
For example, if you set Anchor to Bottom, the distance between the control's bottom edge and the bottom of its parent will not change, so the control will move down as you resize the form.
If you set Anchor to Top | Bottom, the control will resize vertically as you resize the form.

To make a control resize with the form, set the Anchor to all four sides, or set Dock to Fill.

like image 193
SLaks Avatar answered Sep 22 '22 13:09

SLaks