简体   繁体   English

如何使组件根据表单大小的更改来调整大小?

[英]How to enable components to resize according to the change in the form size?

I made a simple button based form for a particular resolution, say, 800*480. 我为特定分辨率(例如800 * 480)制作了一个基于按钮的简单表单。

I want the buttons to automatically resize themselves when used on a higher resolution. 我希望按钮在以更高的分辨率使用时能够自动调整其大小。

I have six buttons of equal size placed as shown and I have used the following anchor properties 如图所示,我放置了六个大小相等的按钮,并且使用了以下锚点属性

[TOP,LEFT]          [TOP,RIGHT]

[LEFT]               [RIGHT]

[BOTTOM,LEFT]       [BOTTOM,RIGHT]

I want the buttons to increase their size as well. 我也希望按钮也增加尺寸。 On the higher resolution, the screen looks empty as all the buttons shift toward the periphery of the screen 在较高的分辨率下,屏幕上的所有按钮都移向屏幕外围,因此屏幕看上去空着

If I use the following config, the buttons overlap each other 如果我使用以下配置,则按钮彼此重叠

[TOP,LEFT,RIGHT]          [TOP,RIGHT,LEFT]

[LEFT,RIGHT]               [RIGHT,LEFT]

[BOTTOM,LEFT,RIGHT]       [BOTTOM,LEFT,RIGHT]

What should I do? 我该怎么办?

I am using Visual C# 我正在使用Visual C#

Add a TableLayoutPanel to your form, with 3 rows and 2 columns. TableLayoutPanel添加到具有3行2列的表单中。

Set Dock property to Fill Dock属性设置为Fill

Put each of your buttons in a cell of the TableLayoutPanel and set their Dock property to Fill 将每个按钮放在TableLayoutPanel的单元格中,并将其Dock属性设置为Fill

You need to set all of your buttons' "Anchor" properties to Top, Bottom, Left, Right . 您需要将所有按钮的“锚点”属性设置为Top,Bottom,Left,Right

This keeps them in place, but also resizes them. 这样可以将它们固定在适当的位置,但也可以调整它们的大小。 Make sure the buttons' "AutoSize" -property is set to false . 确保按钮的“ AutoSize” -property设置为false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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