0

I use some code to add Objects to Controls List of a FlowLayoutPanel. When the controls get added, the vertical scroll bar appears (if necessary) as I set AutoScroll to True.

I also have this event handler:

private void Form1_Resize(object sender, EventArgs e)
{
    resultsFlow.Width = this.Width - resultsFlow.Left;
    resultsFlow.Height = querySetupPanel.Height = this.Height;
}

When I resize my form, the scroll bar disappears regardless of content's height being more than panel's height.

I tried setting minimum and maximum size for both my Form and my panel as suggested in a similar question, but that doesn't work with mine.

Also, when I restore my window from Maximum state to normal, sometimes panel's content don't get repositioned properly.

I'm pretty sure I'm resizing the panels correctly based on the positioning.

Does anyone has any idea what is going on?

Ramtin Soltani
  • 2,650
  • 3
  • 24
  • 45
  • The code is broken, hard to reason out what could happen. You *must* use the ClientSize property instead. Right now the FLP extends too far to the right and way too far towards the bottom. – Hans Passant Apr 10 '15 at 14:21
  • Looks like you should just anchor that panel instead. – LarsTech Apr 10 '15 at 17:05
  • @HansPassant The ClientSize worked well. Does the regular Form.Size include the borders (frames) of the window? And can you post your comment (+ a little more explanation of the difference between ClientSize and Size) as an answer so I can mark it as accepted? – Ramtin Soltani Apr 10 '15 at 21:57
  • @LarsTech What's the main use of Anchor property? (I know these are simple questions, but I've started learning C# just a few days ago! Thanks in advance) – Ramtin Soltani Apr 10 '15 at 22:01
  • On the Anchor property for the panel, highlight the four stems: left, top, right, bottom. Remove your resize code. Now your panel will move with your form when the size changes. – LarsTech Apr 10 '15 at 22:05

1 Answers1

1

Please do the following:

  1. Set Panel Anchor properties to default i.e. Top, Left.
  2. Set AutoSize to False.
  3. Set AutoScroll to True.

That's it. It worked for me. However, if you want to always show the scrollbar, set AutoScrollMinSize to a value that is greater than the actual size. Hope that helps. Thanks.

assembler
  • 3,098
  • 12
  • 43
  • 84
Maqsood
  • 11
  • 2