Windows Forms app autoscaling with form

I am newbie. Designing a form that can be resized and I want my text boxes, labels and buttons to resize to fit the form, can someone tell me how to do this?

+3


source to share


1 answer


It depends on the type of layout you want. The "basic tools" you have to do are the following properties: Anchor and Dock .

Anchor

With the Anchor property, you "anchor" the side of an element to the side of your container. For example, if you place a button in the lower right corner of a window, and you set Bottom Right to Anchor, then when you resize the form, the button will keep its relative position in that corner. Now imagine that you place a multi-line text box on the form, resize as needed (for example, 4 pixels top, left and right, and 128 px height) and set the Anchor property to "Left, Top, Right". When you resize a form that will support its height, but it will resize to keep its margins (so if you make the form wider, its width will increase).

Dock



The dock is different. With docking, you "tell" the layout manager to use all the available space in one direction. For example, if you set it to Left, your control will retain its width, but it will use all the available height and position it as much as possible. You can have multiple controls set up in a container, imagine you have 5 top-docked text boxes inside a form. They will fold to the top of the form using the full width (and resizing). Another example: top docking control (as banner) and Filled docking control (as main content). Remember that when docking the order of the controls (if you first place the Fill control,it will use ALL of the available space and the top dock controls will overlap).

More

Also, you have layout controls (tables and stacks). They are very easy to use and 30 minutes of "experimenting" will clarify much better than a long text.

+2


source







All Articles