Reputation: 1037
I want to change size of picturebox(and image inside) when I change size of the form. But when I do like this
private void Form2_Resize(object sender,EventArgs e)
{
pictureBox1.Width = this.Width;
pictureBox1.Height = this.Height;
}
size of picture doesn't change. What is wrong?
Upvotes: 0
Views: 1197
Reputation: 8269
Make sure that you have hooked the Form2_Resize
event handler above to the Resize
event of your form.
Go to the designer, click on the form, and go to the Events list in the properties box, and make sure you select Form2_Resize
for the Resize
event.
Other than that, you might want to consider docking the picture box to the form as the others are suggesting.
Upvotes: 1
Reputation: 776
I think the resize event fires when the form starts to change it's size. Try to delay your picturebox resize logic till the form is done resizing.
Easiest way however would be to use anchors or dock the picturebox...
Upvotes: 1
Reputation: 13248
If your picturebox
is not docked
try making it docked by setting it's docked property
then it will work.
Upvotes: 1