简体   繁体   中英

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?

尝试

MyPanel.ScrollBars = ScrollBars.Auto

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);

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM