0

I have a GroupBox, and inside that GroupBox is a Panel with properties:

  • .AutoSize = false
  • .AutoScroll = true
  • .Dock = Fill
  • .AutoSizeMode = GrowAndShrink

I create controls in that (Scroll)Panel at runtime and I can also delete those at runtime. Those controls are again GroupBoxes and those can expand/collapse when the user clicks on a button.

The problem is, that now during runtime I get dead space where no control is and I have no idea why. When the resizing from my GroupBoxes inside the Panel happens something goes wrong and now the Panel's ScrollBar can scroll far more up (where no control is anymore).

Does anybody know why this happens and how I can prevent my Panel to have a Scroll-Bar bigger than the actual scrollable content?

Thanks in advance

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
V.Kirsch
  • 13
  • 5
  • The issue may be with the Dock = fill along with AutoSize = false and AutoSizeMode = GrowAndShrink. See : https://stackoverflow.com/questions/154543/panel-dock-fill-ignoring-other-panel-dock-setting – jdweng Aug 01 '23 at 13:11
  • What about using a FlowLayoutPanel instead? Its LayoutEngine is already handling this situation (when you remove / dispose Controls in a `SuspendLayout()` / `ResumeLayout(true)` section) – Jimi Aug 01 '23 at 15:35

1 Answers1

0

I got it. Seems like

.AutoScrollPosition = new Point(0, 0);

Before removing the controls prevents that from happen.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
V.Kirsch
  • 13
  • 5