简体   繁体   English

锚定/停靠有问题时控件的大小

[英]Size of controls when anchoring/docking is problematic

I'm having some problems with anchoring and resizing stuff in my forms. 我在锚定和调整表单中的内容时遇到一些问题。 在此处输入图片说明

This (above) is what the control looks like in the first instance when the user's focus is on groupbox1. 当用户将焦点放在groupbox1上时,控件在第一个实例中的外观(上面)。 All good. 都好。 Notice groupbox2 is anchored on all 4 sides. 注意,groupbox2固定在所有4个面上。

在此处输入图片说明

Now, when the user's focus shifts to groupbox2 a couple of things happen (above). 现在,当用户的焦点转移到groupbox2上时,发生了几件事。 Groupbox2.Top is then set to be just below groupbox1. 然后将Groupbox2.Top设置为刚好低于groupbox1。 Firstly groupbox1 shrinks a bit to only display the most important information. 首先,groupbox1缩小了一点,只显示最重要的信息。 The problem here (I think) is that as soon as groupbox1 shrinks and groupbox2 is shifted upwards dynamically, it doesn't resize to still fill the bottom half of the control, but leaves a silly space just underneath groupbox2. 这里的问题(我认为)是,一旦groupbox1缩小并且groupbox2动态向上移动,它就不会调整大小以仍然填充控件的下半部分,而是在groupbox2下方留出了一个愚蠢的空间。 Groupbox2 does still grow correctly when the form is resized, because it is anchored on all 4 sides. 调整窗体大小时,Groupbox2仍然可以正确增长,因为它固定在所有4个面上。 However the problem is that silly little unused space beneath groupbox2. 但是问题是在groupbox2下几乎没有多少可利用的空间。

在此处输入图片说明

This (above) is what I want to happen. 这(上面)是我想要发生的事情。 When focus is on groupbox2, it should fill all remaining space underneath groupbox1. 当焦点位于groupbox2上时,它应填充groupbox1下的所有剩余空间。

Dock.Bottom doesn't really do the trick, and Dock.Fill covers groupbox1 (which it shouldn't). Dock.Bottom并不能真正解决问题,而Dock.Fill覆盖了groupbox1(不应该这样做)。 I can do this by setting the top and height properties dynamically, but have been cautioned several times against using height/width in code. 我可以通过动态设置topheight属性来做到这一点,但是已经多次警告不要在代码中使用height / width。

Any other solutions? 还有其他解决方案吗?

Try adding both of them to a Panel , 尝试将它们都添加到Panel
make groupBox1 Dock.Top, groupBox2 Dock.Fill 制作groupBox1 Dock.Top,groupBox2 Dock.Fill
and the Panel Dock.Fill as well (or anchor on all sides, if there are other Controls on the Form as well). 以及Panel Dock.Fill(如果在窗体上还存在其他控件,则在所有方面都锚定)。
If one GroupBox is covering the other, it means they are in the wrong order. 如果一个GroupBox覆盖了另一个,则表示它们的顺序错误。 To change that, select one of them and then 'Send to Back' or 'Bring to Front'. 要更改此设置,请选择其中一个,然后单击“发送到背面”或“移到前面”。
There will be no need to set the Top of groupBox2 anymore. 不再需要设置groupBox2的顶部。 It should automatically fill up the space underneath groupBox1. 它应该自动填充groupBox1下的空间。

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

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