0
votes

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?

3
Is the property SizeMode set to Auto? Or Stretch?user2153378
@Hypenate, as I wrote, Size mode is set to Normal, which is importantKorsaR

3 Answers

1
votes

You need to change your picturebox properties...

    PictureBox.SizeMode = SizeMode.Stretch;
0
votes

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?

0
votes

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.