我已经阅读了几个堆栈溢出问题,但没有找到解决我的问题的好办法。如何在调整窗体大小时调整控件的大小?当表格变得更大或更小时,我希望它们变得更大或更小。调整窗体大小的控件
在visual basic中,这对于form.Zoom属性(当然不需要调整控件的大小,但解决了我需要的)很容易。不幸的是,这在C#winforms中不可用。
下面是一些其他的事情我已经试过没有运气:
private void formMain_Resize(object sender, EventArgs e)
{/*
double scale;
this.scaleWidth = (float)this.Width/(float)this.origWidth;
this.scaleHeight = (float)this.Height/(float)this.origHeight;
if (this.scaleHeight > this.scaleWidth)
{
scale = this.scaleHeight;
}
else
{
scale = this.scaleWidth;
}
foreach (Control control in this.Controls)
{
control.Height = (int)(control.Height * this.scaleHeight);
control.Width = (int)(control.Width * this.scaleWidth);
this.Refresh();
// control.Font = new Font("Verdana", control.Font.SizeInPoints * heightRatio * widthRatio);
}
///////This scaling didnt work for me either
//this.Scale(new SizeF(this.scaleWidth, this.scaleHeight));
//this.Refresh();
*/
}
如果我在另一个堆栈溢出的问题,我希望能看到它忽视了代码actualy 工作样品,但那些我发现类似于那些不起作用的那些。
也许我在滥用它,并且有人可能会发布示例代码来向我们这些不断问这个问题的人展示如何解决问题。
此外,我试图使用一些锚/对接工具,认为他们会自动允许它,但它没有。
你已经使用了dock和anchor属性.....试着用更好的方式使用它们......他们应该是你成功的关键我猜。我也可以要求提供一个用户界面的屏幕截图吗? – Sandy 2013-02-28 11:05:57