I have a panel on a form, with the panel's AutoScroll property set to True.

On that panel I have placed several GroupBox controls, which take up more space than the panel does - thus, the panel sprouts a vertical scroll bar.

One of the panels can change height at runtime if need be (I programmatically set its height based on the amount of text it contains):

groupBox1.Height = label1.Height + label1.Top + 10;

This works fine if the panel increases in height - the GroupBoxes below it "move down." However, if the panel decreases in height, the GroupBoxes below do not "move up."

I know I can move the groupbox controls that are below upwards programmatically, but I'm thinking there must be a better/less fussy way of doing it than that...

有帮助吗?

解决方案

Replace the Panel with a FlowLayoutPanel instead and this will become automatic.

(you might want to turn off the wrapping of the FL-Panel)

其他提示

Set their docking property to Top. Then change the Z order of the children to specify their display order.

GroupBox1.Dock = DockStyle.Top;
GroupBox2.Dock = DockStyle.Top;
GroupBox3.Dock = DockStyle.Top;

If groupbox1 grows or shrinks the other 2 panels will move to accommodate.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top