I'm trying to expand my form depending on the resolution of the selected image on the picturebox. But it seems like the picturebox size is not changing when I change the image... any help?
我正在尝试根据图片框上所选图像的分辨率扩展我的表单。但是,当我更改图像时,似乎图片框大小没有变化...任何帮助?
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();
This is only the part of the code which I need a fix. The rest is all right and the picturebox is showing the image I select, but it's not changing sizes.
这只是我需要修复的代码的一部分。其余的都没问题,图片框显示我选择的图像,但它没有改变大小。
1 个解决方案
#1
0
Oh I just figured it out guys, I changed
哦,我只是想出来的人,我改变了
This part:
这部分:
pictureBox1.ImageLocation = reader["imagem"].ToString();
To this:
对此:
pictureBox1.Image = Image.FromFile(reader["imagem"].ToString());
#1
0
Oh I just figured it out guys, I changed
哦,我只是想出来的人,我改变了
This part:
这部分:
pictureBox1.ImageLocation = reader["imagem"].ToString();
To this:
对此:
pictureBox1.Image = Image.FromFile(reader["imagem"].ToString());