C#容器 - 在调整大小时垂直填充空格

时间:2023-02-09 21:47:12

I'm new to C# and I've been working on a small project to get the feel with Visual Studio 2008. I'm designing the GUI in C#, and I have a TabControl with three GroupBoxes. These three GroupBoxes are anchored to the left and right of the screen and work perfectly when resized horizontally.

我是C#的新手,我一直致力于开发一个小项目来感受Visual Studio 2008.我正在用C#设计GUI,我有一个带有三个GroupBox的TabControl。这三个GroupBox锚定在屏幕的左侧和右侧,在水平调整大小时可以正常工作。

I would like these three boxes to take up 33% of the height of the screen, and gracefully resize. I've tried messing around with anchoring, but I can't seem to find the answer. I've also been searching for something similar, but unfortunately, searching for positioning containers yields all CSS and HTML stuff.

我希望这三个盒子占据屏幕高度的33%,然后优雅地调整大小。我试过搞乱锚定,但我似乎无法找到答案。我也一直在寻找类似的东西,但不幸的是,搜索定位容器会产生所有CSS和HTML的东西。

This seems like a pretty common thing to do, but I can't seem to find an easy to way to do it. If someone could point me in the right direction, I'd greatly appreciate it.

这似乎是一件很常见的事情,但我似乎找不到一个容易实现的方法。如果有人能指出我正确的方向,我会非常感激。

Thanks!

3 个解决方案

#1


Try out the TableLayoutPanel. I believe it does exactly what you want. It allows you to define columns and rows within its area, specifying their width (for columns) and height (for rows) in percentages or pixels. You can then drop a group box into each cell and set its Dock property to Fill, and it will nicely resize along with the cell when the TableLayoutPanel resizes (which can be easily achieved by using docking or anchoring).

试试TableLayoutPanel。我相信它完全符合你的要求。它允许您在其区域内定义列和行,以百分比或像素为单位指定宽度(对于列)和高度(对于行)。然后,您可以将一个组框放入每个单元格并将其Dock属性设置为Fill,当TableLayoutPanel调整大小时,它将与单元格一起很好地调整大小(可以通过使用对接或锚定轻松实现)。

#2


This is really a shot in the dark but maybe you could try using split-panels ?

这真的是在黑暗中拍摄,但也许你可以尝试使用分屏?

Edit: I've just checked in Visual Studio and I think the TableLayoutPanel might do what you want.

编辑:我刚刚检查了Visual Studio,我认为TableLayoutPanel可能会做你想要的。

Edit2: dang, beaten to the punch :)

编辑2:当,殴打拳打:)

#3


Handle the form's Resize event: Add code to compute the new size/position of the controls in there. Beware to interferences with the controls' Anchor property. You may have to Anchor to None and compute left and right position yourself as well.

处理表单的Resize事件:添加代码以计算其中控件的新大小/位置。注意干扰控件的Anchor属性。你可能需要锚定到无,并自己计算左右位置。

Since you're learning, I guess you prefer not to receive a full solution but rather a direction. No code from me then ;-)

既然你正在学习,我想你不希望得到一个完整的解决方案,而是一个方向。那时没有代码;-)

#1


Try out the TableLayoutPanel. I believe it does exactly what you want. It allows you to define columns and rows within its area, specifying their width (for columns) and height (for rows) in percentages or pixels. You can then drop a group box into each cell and set its Dock property to Fill, and it will nicely resize along with the cell when the TableLayoutPanel resizes (which can be easily achieved by using docking or anchoring).

试试TableLayoutPanel。我相信它完全符合你的要求。它允许您在其区域内定义列和行,以百分比或像素为单位指定宽度(对于列)和高度(对于行)。然后,您可以将一个组框放入每个单元格并将其Dock属性设置为Fill,当TableLayoutPanel调整大小时,它将与单元格一起很好地调整大小(可以通过使用对接或锚定轻松实现)。

#2


This is really a shot in the dark but maybe you could try using split-panels ?

这真的是在黑暗中拍摄,但也许你可以尝试使用分屏?

Edit: I've just checked in Visual Studio and I think the TableLayoutPanel might do what you want.

编辑:我刚刚检查了Visual Studio,我认为TableLayoutPanel可能会做你想要的。

Edit2: dang, beaten to the punch :)

编辑2:当,殴打拳打:)

#3


Handle the form's Resize event: Add code to compute the new size/position of the controls in there. Beware to interferences with the controls' Anchor property. You may have to Anchor to None and compute left and right position yourself as well.

处理表单的Resize事件:添加代码以计算其中控件的新大小/位置。注意干扰控件的Anchor属性。你可能需要锚定到无,并自己计算左右位置。

Since you're learning, I guess you prefer not to receive a full solution but rather a direction. No code from me then ;-)

既然你正在学习,我想你不希望得到一个完整的解决方案,而是一个方向。那时没有代码;-)