ArnoBM老哥的改版
namespace WinFormsApp1
{
public partial class Form1 : Form
{
private float width;
private float height;
public Form1()
{
InitializeComponent();
width = this.Width;
height = this.Height;
}
private void Form1_Resize(object sender, EventArgs e)
{
float newx = (this.Width) / width;
float newy = (this.Height) / height;
width = this.Width;
height = this.Height;
foreach (Control con in this.Controls)
{
try{
con.Width = Convert.ToInt32(con.Width* newx);//宽度
con.Height = Convert.ToInt32(con.Height * newy);//高度
con.Left = Convert.ToInt32(con.Left * newx);//左边距
con.Top = Convert.ToInt32(con.Top * newy);//顶边距
}
catch
{
Console.WriteLine("跳过一个异常");
}
}
}
}
}
原大小 放大后