https://blog.csdn.net/qq_38628970/article/details/103734246

    点击主界面,鼠标右键查看代码在界面初始化函数:InitializeComponent();后面加入下面代码:

    1. public Form2()
    2. {
    3. InitializeComponent();
    4. int count = this.Controls.Count * 2 + 2;
    5. float[] nature = new float[count];
    6. int i = 0;
    7. nature[i++] = Size.Width;
    8. nature[i++] = Size.Height;
    9. foreach (Control ctrl in this.Controls)
    10. {
    11. nature[i++] = ctrl.Location.X / (float)Size.Width;
    12. nature[i++] = ctrl.Location.Y / (float)Size.Height;
    13. ctrl.Tag = ctrl.Size;
    14. }
    15. Tag = nature;
    16. }

    回到主界面,点击闪电标志,找到主界面的所有事件,然后双击Resize右边空白,就生成了主界面的Resize事件。

    1. private void Form2_Resize(object sender, EventArgs e)
    2. {
    3. float[] percent = (float[])Tag;
    4. int i = 2;
    5. foreach (Control ctrl in this.Controls)
    6. {
    7. ctrl.Left = (int)(Size.Width * percent[i++]);
    8. ctrl.Top = (int)(Size.Height * percent[i++]);
    9. ctrl.Width = (int)(Size.Width / (float)percent[0] * ((Size)ctrl.Tag).Width);
    10. ctrl.Height = (int)(Size.Height / (float)percent[1] * ((Size)ctrl.Tag).Height);
    11. }
    12. }