C#代码:
public void AutoScale(Form frm)
{
frm.Tag = frm.Width.ToString() + "," + frm.Height.ToString();
frm.SizeChanged += new EventHandler(frmScreen_SizeChanged);
}
private void frmScreen_SizeChanged(object sender, EventArgs e)
{
string[] tmp = ((Form)sender).Tag.ToString().Split(',');
float width = (float)((Form)sender).Width / (float)Convert.ToInt16(tmp[0]);
float heigth = (float)((Form)sender).Height / (float)Convert.ToInt16(tmp[1]) 代码生成器 ;
((Form)sender).Tag = ((Form)sender).Width.ToString() + "," + ((Form)sender).Height;
foreach (Control control in ((Form)sender).Controls)
{
control.Scale(new SizeF(width, heigth));
}
}
public frmScreen()
{
InitializeComponent();
AutoScale(this);
}
本文介绍了一个使用C#实现的窗体自动缩放功能,通过记录窗体初始大小并在窗体尺寸变化时调整所有子控件的大小来保持布局比例不变。该方法适用于需要动态调整界面的应用程序。

被折叠的 条评论
为什么被折叠?



