2

I have a Form, inside the Form there is a Panel.

I would like the Panel to Fill the Form, but only if the Form is bigger then a minimum size.

Till this point it is already working.

When the Form is smaller then the Panel, I would like to have scrollbars. This is not working.

I set the AutoScroll in the form. The scrollbars working only if the Panel has a fixed size and the Form is smaller. If I set the Panel to Fill the form and set the minimum size, the scrollbars not appearing.

The following code snippet is from InitializeComponent of the Form

this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.MinimumSize = new System.Drawing.Size(250, 250);
this.AutoScroll = true;

In the picture you can see that the Panel is bigger then the Form, but there is no scrollbar.

enter image description here

3
  • Can you post what code you are using so far? Sounds like maybe the panel is shrinking with the form perhaps. Feb 28, 2017 at 13:14
  • @JoshuaHysong I added some more information
    – dvjanm
    Feb 28, 2017 at 13:32
  • You have to set "AutoScrollMinSize". Feb 28, 2017 at 13:48

1 Answer 1

3

You also need to set the forms AutoScrollMinSize property

this.AutoScroll = true;
this.AutoScrollMinSize = new System.Drawing.Size(250, 250);

Make this the same as your panels minimum size and the scrollbars will appear as desired only when the form is smaller than the panel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.