https://blog.csdn.net/qq_38628970/article/details/103734246
点击主界面,鼠标右键查看代码在界面初始化函数:InitializeComponent();后面加入下面代码:
public Form2(){InitializeComponent();int count = this.Controls.Count * 2 + 2;float[] nature = new float[count];int i = 0;nature[i++] = Size.Width;nature[i++] = Size.Height;foreach (Control ctrl in this.Controls){nature[i++] = ctrl.Location.X / (float)Size.Width;nature[i++] = ctrl.Location.Y / (float)Size.Height;ctrl.Tag = ctrl.Size;}Tag = nature;}
回到主界面,点击闪电标志,找到主界面的所有事件,然后双击Resize右边空白,就生成了主界面的Resize事件。
private void Form2_Resize(object sender, EventArgs e){float[] percent = (float[])Tag;int i = 2;foreach (Control ctrl in this.Controls){ctrl.Left = (int)(Size.Width * percent[i++]);ctrl.Top = (int)(Size.Height * percent[i++]);ctrl.Width = (int)(Size.Width / (float)percent[0] * ((Size)ctrl.Tag).Width);ctrl.Height = (int)(Size.Height / (float)percent[1] * ((Size)ctrl.Tag).Height);}}
