//控件随窗体自动缩放
string[] tmp = new string[2];
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));
}
使用该代码注意事项:1,此段代码基本通用。2,此段代码写在窗体的加载事件中。3,若窗体需要缩小,请再写在窗体的SizeChanged事件中。