1

I am having difficulty getting both the vertical and horizontal scroll bars to behave as desired in my situation. The page in question has multiple sections that can be expanded and collapsed (only one can be expanded at a time). To try and demonstrate the layout of my page I'm going to use nesting and perhaps a silly naming convention to be as clear as possible:

  • ucParent
    • pnlParent
      • pnl1Title
      • pnl1
        • uc1
      • pnl2Title
      • pnl2
        • uc2
      • pnl3Title
      • pnl3
        • uc3-1
        • uc3-2
        • uc3-3

And so on. Now, pnlParent has dock=fill, while the child panels are dock=top. All the pnlXTitle panels have buttons that trigger the expanding/collapsing behavior by setting their respective panels directly underneath to enabled=visible=false.

I'm wanting the horizontal and vertical scroll bars to show up as needed when the window is resized and hiding content, however I am not being successful at eliciting this behavior.

  • With ucParent.AutoScroll=false and pnlParent.AutoScroll=true only the vertical scroll bar is present.
  • With ucParent.AutoScroll=true and pnlParent.AutoScroll=false neither scrollbar works.
  • With both ucParent.AutoScroll=true and pnlParent.AutoScroll=true only the vertical scroll bar is present.

In all the above examples, AutoScroll=false for all the other panels and user controls. From what I've read so far, I fear the dock=top setting may be interfering with the horizontal scroll bar behavior. I can force it to display and work by using AutoScrollMinSize, but the panels are of different sizes making this feel like much more of a hack than a proper solution.

Through my searching I found a good number of previous discussions revolving around Windows Forms and scrollbars, but I didn't find anything specific enough I feel I can confidently determine the necessary direction for my application. I would very much appreciate any information you could share that would shed light on why the scroll bars are not working as desired and how that can be remedied.

Thank you!

BZbANKFDpN
  • 33
  • 4

1 Answers1

1

The problem you're experiencing has to do with the way that docking resizes your controls to fit horizontally within the form.

When you dock a control to the top of its container, it is stretched to fit within the container. Consequently, no part of it falls outside of the container, and there is no need to display the horizontal scroll bar. This is why your scroll bar isn't appearing.

This behavior is by design.

Mike Hofer
  • 16,477
  • 11
  • 74
  • 110
  • Thank you for the response! I was afraid that was the case. It makes sense it would work that way. However, I have user controls inside those child panels that are large enough they are being hidden when the window is resized. Would using the AutoScrollMinSize then be the best workaround for this issue? – BZbANKFDpN Jul 06 '15 at 20:14
  • You shouldn't dock the control if that's the behavior you desire. Instead, set the Anchor property, as explained in this answer here: http://stackoverflow.com/questions/1222830/how-to-make-scrollbars-appear-in-a-resizable-panel-when-the-contained-control-is – Mike Hofer Jul 06 '15 at 20:18
  • I'm not yet sure how to replicate the expanding/collapsing behavior of the currently top docked panels by using anchors, but I'll keep thinking about that. Thank you for the link! – BZbANKFDpN Jul 06 '15 at 20:34