Martijn Martijn - 30 days ago 14
C# Question

C# Panel autoscroll doesn't work

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.

Answer Source

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.