简体   繁体   中英

Picture box does not resize when it has image

I have a windows form and picture box on it, wich has anchor property set to Top, Bottom, Left, Right. Size mode is set to Normal, which is important. The problem is that when picture box is empty, it resizes with the form, but once I set an image to it, when I resize form, it stays the same size. The only idea I have in order to fix this is to save image temporarily, clear picture box, then once it's resized count scaling value, resize picture and then set it back, but as for me it's a pretty lame approach. Is there any way I can do it simplier?

您需要更改图片框属性...

    PictureBox.SizeMode = SizeMode.Stretch;

I tried it...

Anchor: Top, Bottom, Left, Right

SizeMode: Normal

Load image in picturebox:

var ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    pictureBox1.ImageLocation = ofd.FileName;
}

I can resize the form and the picturebox resizes with the form --> it works.

May you have changed another property, which avoids the resizing?

Go to the form's Designer.cs and under the PictureBox entries, add the following:

this.PictureBox.Dock = System.Windows.Forms.DockStyle.Fill;

That way, no matter what size you re-size the window to, the image will take up the full space of the window.

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