即使设置了 Dock 属性,也可以强制执行 Margin 吗?
我有一个 WinForms Form
,上面有一些控件。它们都是 GroupBox
控件,我希望它们堆叠在一起,并在它们之间设置垂直边距。我已将 Dock 属性设置为 Top,它可以正常堆叠它们,但忽略边距(控件彼此尽可能靠近)。
这些边距仍然可以以某种方式强制执行吗?基本上,它会计算常规停靠位置(就好像边距为 0),然后应用边距。这样的事情可能吗?
我尝试过的另一种方法是使用 FlowLayoutPanel
和 TopDown
选项。但是,然后我需要手动设置大小和左/右锚点。
有没有简单的方法来完成这个场景,或者我应该坚持我已经拥有的?
I have a WinForms Form
with a few controls on it. All of them are GroupBox
controls and I want them stacked, with a vertical margin set between them. I have set the Dock
property to Top and it stacks them alright, but ignores the margin (controls are as close to each other as they can be).
Can these margins still somehow be enforced? Basically, it would calculate the regular docked position (as if the margin was 0) then apply the margin. Is something like this possible?
The other way I've tried this is with FlowLayoutPanel
with TopDown
option. However, then I need to manually set the size and Left/Right anchors.
Is there any easy way to acomplish this scenario or should I stick with what I already have?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将每个组框放置在面板中,将面板停靠属性设置为顶部,将组框停靠属性设置为填充。然后在面板上设置Padding。
Place each GroupBox in a Panel, Set Panel Dock Property to Top, Group Box Dock Property to Fill. Then set Padding on the panels.
设置的停靠属性将忽略 GroupBox 控件之间的填充属性,因此,最好的选择是使用 Flow 或 Table 面板来执行此操作。
The set docking property will ignore your padding properties between GroupBox controls, so yes, your best bet is the Flow or Table panels to do this.
添加一个停靠在每个文本框之间的虚拟透明面板,其高度等于您所需的确切距离。
Add a dummy transparent panel docked between each textbox with a height equal to the exact distance you require.