8

What are the rules which I have to respect to make the Form scrollable...

I simple set the Property AutoScroll to true. I also tried while Auto Scroll is true, to set AutoSize to true/false, but none of these worked... also tried to put Panel and added all components in there... still nothing...

Maybe using V or HScrollBar can help, but i really don't know how to link it with the Form...

form.AutoScroll = true;
formMainLayout.AutoScroll = true;
rootPanel.AutoScroll = true;
rory.ap
  • 34,009
  • 10
  • 83
  • 174
jovanMeshkov
  • 757
  • 5
  • 12
  • 29

6 Answers6

7

I was also having the same problem, I managed to fix it... All the child controls inside the panel had a Left & Right anchor, and when I only set the anchor to Top, the scrollbars where working fine.

I am not sure as to why the Left and Right anchor (of the child controls) forces the panel not to show scrollbars.

But anyways... hope this will help anyone as of this date.

Sean
  • 182
  • 2
  • 5
6

The content controls the scrolling. The scrollbars do not appear unless they are needed. Usually, there is a property available that you can set to force them to be visible always, and simply disabled until needed.

The AutoScroll property must be true, as you have already found. But then the content of the scrollable control must force the parent control to display the scrollbars. This part is up to how the controls are embedded within the parent.

Try these two experiments:

  1. Place a Panel on your form and dock it to Fill. Set the AutoScroll property of the Panel to true. Into that panel, place a TextBox and set it to dock as Fill as well. Also set MultiLine to true. Run the application, and you will notice that the size of both is simply using the available space...no scrolling can occur because neither the Panel, nor its TextBox become larger than the space they occupy.

  2. Perform the same steps as in #1, but this time, do not dock the TextBox. Instead, set it to a large size, something that you know will be larger than the amount of Panel that is visible. Running the application should now produce a scrolling Panel.

Hopefully this little test helps to demonstrate what is controlling the scroll on a form.

DonBoitnott
  • 10,787
  • 6
  • 49
  • 68
  • Sorry but I am not sure about what you meant with "the Form itself isn't a scrollable control". The form is as scrollable as any other control: autoscroll + conditions met (contained controls outside the boundaries) or vscrollbar/hscrollbar in it. Also, I am not too sure about the actual/direct applicability of what you say to answer the question "why when I set AutoScroll to true I don't see the bar?". – varocarbas Jul 22 '13 at 15:12
  • 1
    @varocarbas Your point is well taken. I have removed that part of my answer. In regard to the latter part of your comment, this is the question I am attempting to demonstrate an answer to: "What are the rules which I have to respect to make the Form scrollable". – DonBoitnott Jul 22 '13 at 15:50
  • I set the root panel to Dock -> None... and it seems fine, but the problem is that I want some Controls to use all available size of the Form while some buttons to stay in height static and also width to use all available Form width... so far i achieved it with Dock -> Fill... – jovanMeshkov Jul 22 '13 at 22:10
  • How ever, thank you it helped me somehow, i had to experiment with Size and Fills – jovanMeshkov Jul 24 '13 at 14:54
1

The AutoScroll property should work fine, but most likely you are not using it right: the bar appears only when required. Example: minimum Y of the Form is 0 and minimum Y of one of the controls in it (a TextBox) is -20.

If you want to include a scroll bar no matter what (controls inside the boundaries of the form or not), you can also do it. Sample code (from MSDN) for a vertical scroll bar:

// Create and initialize a VScrollBar.
VScrollBar vScrollBar1 = new VScrollBar();

// Dock the scroll bar to the right side of the form.
vScrollBar1.Dock = DockStyle.Right;

// Add the scroll bar to the form.
Controls.Add(vScrollBar1);
varocarbas
  • 12,354
  • 4
  • 26
  • 37
0

You need to set the properties for the parent panel.

  1. Dock = Fill
  2. Anchor = Top, Left
  3. AutoScroll = true

That's it. Good luck! ^^

Pixs Nguyen
  • 136
  • 1
  • 4
0

note its for vertical scroll

  1. Turn On auto scroll property of your Form. insert one panel and set panel width to the form width and panel height equal to length of your total content or may be 1300 or 1500 as required.

  2. Place panel location as you want set panel anchor property to top. place your all content inside panel.

hope it will solve your problem

0

I had the same problem.

You have to add only this:

this.AdjustFormScrollbars(true);

Gideon
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 10 '22 at 15:45