Reputation: 572
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?
Upvotes: 0
Views: 3725
Reputation: 836
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.
Upvotes: 0
Reputation: 3
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?
Upvotes: 0
Reputation: 1580
You need to change your picturebox properties...
PictureBox.SizeMode = SizeMode.Stretch;
Upvotes: 1