简体   繁体   English

在form_resize事件中设置图片框大小

[英]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. 我认为当表单开始更改其大小时会触发resize事件。 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. 确保已将上面的Form2_Resize事件处理程序挂钩到Form2_ResizeResize事件。
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. 转到设计器,单击窗体,然后转到“属性”框中的“事件”列表,并确保为“ Resize事件选择“ Form2_Resize ”。

Other than that, you might want to consider docking the picture box to the form as the others are suggesting. 除此之外,您可能要考虑其他人建议的将图片框停靠在表单上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM