如何使PictureBox可滚动?

时间:2014-08-22 11:56:03

标签: c# picturebox

在我的表格上,我在Panel中有一个PictureBox 我设置:

MyPanel.AutoScroll = true
MyPictureBox.SizeMode = AutoSize

将图像添加到PictureBox后:

MyPictureBox.Image = Image.FromFile(path);

但是当我打开表格时,我看不到里面有任何滚动条。
有什么不对?

2 个答案:

答案 0 :(得分:1)

尝试

MyPanel.ScrollBars = ScrollBars.Auto

答案 1 :(得分:1)

您可能需要设置PictureBox的高度和宽度,并将Panel的AutoScroll属性设置为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);