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.
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.
From MSDN:
There is currently a limitation in Windows Forms that prevents all classes derived from
ScrollableControlfrom acting properly when bothRightToLeftis enabled andAutoScrollis set toTrue. For example, let's say that you place a control such asPanel— or a container class derived fromPanel(such asFlowLayoutPanelorTableLayoutPanel) — on your form. If you setAutoScrollon the container toTrueand then set theAnchorproperty on one or more of the controls inside of the container toRight, then no scrollbar ever appears. The class derived fromScrollableControlacts as ifAutoScrollwere set toFalse.
The picturebox should not be anchored bottom and right. Instead, resize it to the content to display.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With