none
Anchoring + Auto Scroll + Minimum Size = -Fun

    Question

  • I've run into this problem quite a bit and am not sure how to achieve the layout I am looking for.

     

    I frequently develop user controls that I want to expand to fill their parent control. This is easy, either set the docking to fill, or anchor all four sides to the parent control. The part I'm finding to be a problem is that when the control reaches a certain minimum size, I want it to stop shrinking and have scrollbars kick in. So I set a minimum size for the user control. So now it grows with the parent like it should and shrinks to its minimum size, but the scrollbars of the parent (set to autoscroll) never appear when it becomes smaller than the control's minimum size. Why won't they show up?! (The control I am currently working on is anchored to all 4 sides). Thanks.

    Tuesday, July 10, 2007 7:36 PM

Answers

  • You can use the parent's AutoScrollMinSize property to solve the problem. I set the AutoScrollMinSize  to the same size as the control's minimum which forces the parent to evaluate when to show scrollbars based on the AutoScrollMinSize instead of the size/position of its controls.
    Tuesday, July 10, 2007 11:44 PM

All replies

  • You'll probably have to unanchor the control once you get to your minimum size.
    Tuesday, July 10, 2007 8:15 PM
  • Good thought, thanks. Do you know why autoscroll does not recognize that the control is larger than the client area?
    Tuesday, July 10, 2007 8:41 PM
  • That doesn't really work. The scrollbars appear but there's no gaurantee that the resize event will fire at the exact coordinate that the anchors should be removed or added. So if you resize really quickly it won't fire the event until the parent is way larger or smaller than the size it should be when the anchors are added/removed. The window could be almost full size before it actually re-anchors the control.

     

    What is the purpose of a minimum size property if you cannot enable scrollbars?

    Tuesday, July 10, 2007 10:59 PM
  • You can use the parent's AutoScrollMinSize property to solve the problem. I set the AutoScrollMinSize  to the same size as the control's minimum which forces the parent to evaluate when to show scrollbars based on the AutoScrollMinSize instead of the size/position of its controls.
    Tuesday, July 10, 2007 11:44 PM