简体   繁体   中英

set picturebox size in form_resize event

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?

如果您的图片pictureboxdocked尝试通过设置其停靠property使其停靠,然后它将起作用。

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...

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.

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