VB/C#:相等地调整两个控件的大小 [英] VB / C#: Resizing two controls equally

查看:212
本文介绍了VB/C#:相等地调整两个控件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个窗口,其中将有两个组/面板以及它们之间的一些按钮.我想对尺寸调整行为进行编码,以使窗口扩展时,两个面板增加其宽度,同时保持它们之间的距离恒定.

I have made a window in which I will be having two groups/panels and some buttons in between them. I want to code the resizing behavior in a way that when the window expands, the two panels increase their widths while keeping the distance between them constant.

请查看此样机:

如上所述,我希望调整本地"和服务器"面板的大小,同时保持它们之间的距离相同.如果使用锚点(顶部+左侧+右侧+底部),则左侧面板将与右侧面板重叠,右侧面板的宽度将从窗口中移出.我希望他们平均分配增加的窗口宽度.

As you see above, I want the 'Local' and 'Server' Panels to resize while keeping the distance in between them same. If I use anchors (Top+Left+Right+Bottom), the left panel will overlap the right one and the right's width one will go out of the window. I want them to share the increased width of the window equally.

至于它们之间的按钮,我一直将ancors保留为Top.通过从按钮中删除左锚",当窗口扩展时,它会自动将其自身放置在窗口的中央,这正是我想要的方式.

As for the buttons in between, I have kept ancors as Top only. By removing Left anchor from button, it automatically places itself in the center of the window when window is expanded, which is just the way I want it to be.

有什么想法可以管理面板的大小调整吗?

Any ideas how to manage resizing of panels?

谢谢.

推荐答案

使用 TableLayoutPanel 控件.

首先将TableLayout添加到Form并将其Dock()属性设置为Fill. 接下来,您需要设置3列和2行.将两个按钮添加到中间列,每个按钮都在其自己的行中.然后,设置列值,如下所示: 将两者的行都保留为50%. 现在,将您的两个GroupBox添加到第一行的第一列和第三列中. 对于两个GroupBox,将Dock()设置为Fill,将RowSpan()设置为2. 对于顶部按钮,仅打开底部锚点. 对于底部的按钮,仅转动顶部锚. 对于TableLayoutPanel,将Padding()设置为5,5,5,5.

First add the TableLayout to the Form and set its Dock() property to Fill. Next you'll need to setup 3 columns and two rows. Add the two buttons to the middle column with each one is in its own row. Afterwards, setup the column values so they are like this: Leave the rows at 50% on both. Now add your two GroupBoxes to the 1st and 3rd columns in the 1st row. For both GroupBoxes, set Dock() to Fill, and RowSpan() to 2. For the top Button, turn on only the Bottom Anchor. For the bottom Button, turn only the Top Anchor. For the TableLayoutPanel, set Padding() to 5,5,5,5.

这是我完成后的样子:

Here is what it looked like when I was all done:

调整窗口大小并观察控件的行为...

Resize the window and observe how the controls behave...

这篇关于VB/C#:相等地调整两个控件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆