简体   繁体   中英

How to make controls stretch and shrink when the window is resized?

调整窗口大小时,如何使所有控件都不在一个角上或只是耸耸肩,而是变得更大或更小以与窗口相对应?

You need to Anchor your control(s) on the window.

Basically u (always) anchor your control on Top & Left (that's default anyway).

If you want to stretch your Control horizontal add Right . For vertical stretching add Bottom .

[Properties] (rightclick the control you want to anchor and select properties)

在此处输入图片说明

Use Anchor property of each control to achieve the effect.

For example, if you set it to "Right, Bottom" on a control, it will keep its right and bottom side anchored (set to fixed distance) against the right and bottom edge of the form.

This is sufficient for basic sizing. For advanced sizing, you have to size your controls manually on window resize event.

You might also want to set MinimumSize property of your form to prevent its window to shrink under that size. This way you can prevent unwanted layout distortions like controls clipped or completely hidden behind right or bottom edge of the window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM