Best Way to Resize Windows Forms

I am working on a large C # project with a lot of Windows Forms forms which, even if you can resize the form, the elements in the form do not scale.

How to make the form elements (such as data grid, text areas, etc.) scaled when the user resizes the form?

Almost all forms are subclasses from one particular form, so if there is something that I can do in the base class, that would be great.

+6
c # winforms
source share
2 answers

You must set the Anchor and Dock properties in the controls in the forms.

The Anchor property controls which edges of the control are โ€œconnectedโ€ or โ€œattachedโ€ to the corresponding edges of its form.
For example, if you set Anchor to Bottom , the distance between the bottom edge of the control and the bottom of its parent will not change, so the control will move downward when you resize the form. If you install Anchor on Top | Bottom Top | Bottom , the control will resize vertically when the shape is resized.

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

+15
source share

Use the Anchor and Dock properties.

Anchor allows you to display certain sides of the control in the direction of the parent control.

The Dock will associate the entire control with the parent control side, or it can be configured to populate the contents of the parent control.

Usually you just need to set the snapping to the bottom and right of the parent control, but it becomes more complicated when you have the controls next to each other, then you need to manually resize the controls in the OnResize event of the forms to get them scaled naturally together .

+5
source share

All Articles