Scroll bars on picture box

| August 10, 2010 | 1 Comment

Do you ever think that PictureBox control provided by Microsoft is very nice but with something missing. Yes! You get right that something is  PictureBox not having scroll bar to scroll my big desktop size images. And so finally I have to try other way in PictureBox. BUT now we have the alternative and pretty nice working solution for the problem.

But before I go straight to point I would like to share the some of the way by which you can display your pictures in PictureBox. There is property SizeMode that can be set by System.Windows.Forms.PictureBoxSizeMode:-

  1. PictureBoxSizeMode.Normal – Image is placed in upper-left corner of the PictureBox. And the rest of image (if size of image greater than PictureBox) is clipped.
  2. PictureBoxSizeMode.AutoSize – PictureBox size becomes equal to the size of image.
  3. PictureBoxSizeMode.CenterImage – Image is displayed in center of the PictureBox if image size is small than PictureBox. And if image size is bigger than PictureBox than picture is placed in center and outside edges or corner of picture are clipped.
  4.  PictureBoxSizeMode.StretchImage – Image in PictureBox is shrunk or stretched to fit in PictureBox.
  5. PictureBoxSizeMode.Zoom – Image size is increased or decreased on basis of PictureBox size maintaining ratio.

Adding Scrollbar to PictureBox:

We are just making trick to add scrollbar to PictureBox. Follow steps:

  • Add Panel to Form and set it’s AutoScroll property to true.
  • On Panel add a PictureBox control and Size of PictureBox should be set same as of Panel.
  • Set image in PictureBox by Image property.
  • Set PictureBox SizeMode property to AutoSize.

Now when you run the program, the panel scrollbar would be set accordingly and than you can use them to scroll your PictureBox’s picture. Take care not to add other controls in Panel.

Category: .NET, Tips

Comments (1)

Trackback URL | Comments RSS Feed

  1. The form that the picturebox is, you could also make its AutoScroll property to true to accomplish what you are trying to do!

Leave a Reply

%d bloggers like this: