【发布时间】:2015-12-25 11:47:16
【问题描述】:
我正在尝试根据图片框中所选图像的分辨率来扩展我的表单。但是,当我更改图像时,图片框的大小似乎没有改变......有什么帮助吗?
pictureBox1.ImageLocation = reader["imagem"].ToString();
pictureBox1.Height = pictureBox1.Image.Height;
pictureBox1.Width = pictureBox1.Image.Width;
/*mw and mh are the main width and main heigth,
i used this in case the user selects another
image, then the window returns to it's original
size before changing again.*/
this.Height = mh;
this.Width = mw;
this.Height += pictureBox1.Image.Height;
this.Width = pictureBox1.Image.Width + 16;
if (this.Width < mw)
{
this.Width = mw;
}
this.CenterToParent();
这只是我需要修复的部分代码。其余的都很好,图片框显示我选择的图像,但它没有改变大小。
【问题讨论】:
-
使用 ImageLocation 没问题,但如果接下来要使用 Image 属性,则必须将 WaitOnLoad 属性设置为 True。或者更好的是,使用 LoadCompleted 事件。
标签: c# picturebox