Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Panel autoscroll doesn't work

Tags:

c#

winforms

I have a panel with a picturebox on it. When the content of the picturebox is too large I want scrollbars. I've set the autoscroll set to true on the panel. But when the content of the picturebox is larger then the height of the panel/picturebox no scrollbars are shown.

My panel is anchored top, left, bottom, right. The picturebox is also anchored top, left, bottom, right.

like image 414
Martijn Avatar asked Jan 12 '10 12:01

Martijn


3 Answers

You'll have to set the SizeMode property to AutoSize which causes the PictureBox to automatically resize to the picture's size.

And I think you should drop the anchors and only anchor to the top left. The rest is taken care of automatically by the panel. Because otherwise the PictureBox would probably honor the anchors, being unable to resize itself larger than the panel it contains – leading to no scrollbars again.

like image 103
Joey Avatar answered Sep 24 '22 02:09

Joey


From MSDN:

There is currently a limitation in Windows Forms that prevents all classes derived from ScrollableControl from acting properly when both RightToLeft is enabled and AutoScroll is set to True. For example, let's say that you place a control such as Panel— or a container class derived from Panel (such as FlowLayoutPanel or TableLayoutPanel) — on your form. If you set AutoScroll on the container to True and then set the Anchor property on one or more of the controls inside of the container to Right, then no scrollbar ever appears. The class derived from ScrollableControl acts as if AutoScroll were set to False.

like image 21
serhio Avatar answered Sep 22 '22 02:09

serhio


The picturebox should not be anchored bottom and right. Instead, resize it to the content to display.

like image 43
Henrik Avatar answered Sep 25 '22 02:09

Henrik