【发布时间】:2009-12-31 02:04:27
【问题描述】:
当窗口大小发生变化时,我有几个图片框需要按纵横比调整大小。我假设我可以锚定宽度,但手动设置高度(即锚定左、右和顶部边缘;但不是底部。)但是,如果我尝试更改 Size 属性,我的控件将不会调整大小。为什么那行不通?如何调整控件的大小?
private void Form1_Resize(object sender, System.EventArgs e)
{
int oldWidth = 1280;
int oldHeight = 1024;
int newWidth = webcamPictureBox.Size.Width; // this is auto-resized w/ window; becomes 591
int newHeight = (oldHeight * newWidth) / oldWidth; // this is calculated manually; becomes 472
// Control won't resize if I change the Size property
// Size property stays the same
this.webcamPictureBox.Size = new Size(newWidth, newHeight);
this.thumbnailPictureBox.Size = new Size(newWidth, newHeight);
}
【问题讨论】: