Scrollable form in C #, AutoScroll = true not working

What are the rules that I must follow in order to make the form scrollable ...

I just set the AutoScroll property to true. I also tried, while Auto Scroll true, to set AutoSize to true / false, but none of them worked ... also tried to place the panel and added all the components there ... nothing is the same ...

Maybe using a V or HScrollBar might help, but I really don't know how to associate it with a form ...

 form.AutoScroll = true; formMainLayout.AutoScroll = true; rootPanel.AutoScroll = true; 
+5
source share
3 answers

Content controls scrolling. Scroll bars are not displayed if they are not needed. A property is usually available that you can set to make them always visible, and just turn it off until you need it.

The AutoScroll property should be true , as you already found. But then the contents of the scrollable control should make the parent control display the scroll bars. This part depends on how the controls are embedded in the parent element.

Try these two experiments:

  • Place a Panel on the form and attach it to the Fill . Set the panel's AutoScroll property to true . In this panel, place the TextBox and set it for the dock as Fill . Also set MultiLine to true . Launch the application, and you will notice that the size of both is just the available space ... scrolling cannot happen, because neither the Panel nor its TextBox become larger than the occupied space.

  • Follow the same steps as in # 1, but this time do not attach the TextBox . Instead, set it to a large size, what you know will be larger than the amount of Panel that is visible. Starting the application should now scroll the Panel .

Hopefully this little test will help demonstrate that controls scrolling in a form.

+3
source

I also had the same problem, I managed to fix it ... All the child controls inside the panel had the Left and Right anchor, and when I set the binding only to the top, the scroll bars where they work fine.

I'm not sure why the Left and Right anchor (child controls) causes the panel to not show scrollbars.

But anyway ... hope this helps someone from now.

+3
source

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

If you want to enable the scroll bar no matter what (controls within the borders of the form or not), you can also do this. Sample code ( from MSDN ) for vertical scrollbar:

 // 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); 
0
source

Source: https://habr.com/ru/post/912469/


All Articles