Kliver Max
Kliver Max

Reputation: 5299

How to make a PictureBox scrollable?

On my form i have a PictureBox inside Panel.
I set:

MyPanel.AutoScroll = true
MyPictureBox.SizeMode = AutoSize

After i add image into PictureBox:

MyPictureBox.Image = Image.FromFile(path);

But when i open form i don't see any scrollbars inside.
What can be wrong?

Upvotes: 2

Views: 5412

Answers (3)

coarist
coarist

Reputation: 898

Tips:

  1. Verify that MyPictureBox is inside MyPanel, in other words, MyPanel contains MyPictureBox.
  2. On the Designer, make MyPictureBox significantly smaller than its container MyPanel. Due to AutoSize, it will fill the entire space provided by the container during runtime.
  3. Check that MyPictureBox has property Anchor set to Top, Left but NOT Top, Left, Bottom, Right.

Upvotes: 1

Michal Kalous
Michal Kalous

Reputation: 114

You have to probably set height and width of PictureBox and set AutoScroll property of Panel to true.

Panel MyPanel = new Panel();
PictureBox pictureBox1 = new PictureBox();

Image image = Image.FromFile("image.png");

pictureBox1.Image = image;
pictureBox1.Height = image.Height;
pictureBox1.Width = image.Width;

MyPanel.Controls.Add(pictureBox1);
MyPanel.AutoScroll = true;
this.Controls.Add(MyPanel);

Upvotes: 1

Microsoft DN
Microsoft DN

Reputation: 10020

Try

MyPanel.ScrollBars = ScrollBars.Auto

Upvotes: 1

Related Questions