Search code examples
c#winformsscrollscrollbarpicturebox

How can I get scrollbars on Picturebox


I have PictureBox picture.

I use:

picture.Size = bmp.Size;
picture.Image = bmp;

Let's say there are two integers maxWidth and maxHeigth.
I want to add vertical/horizontal scrollbar to picture when its size exceeds maxWidth and/or maxHeight. How can I do that?


Solution

  • You can easily do it with a Panel Control

    Insert a panel to your form, say panel1 and set

    panel1.AutoScroll = true;

    insert a PictureBox to the Panel, say picture and set

    picture.SizeMode = PictureBoxSizeMode.AutoSize;
    

    and set the Image

    picture.Image = bmp;