winform 窗体最大化时,里面的控件怎么一起按照比例变大?
现在winform 窗体最大化时,控件还是那么小,很丑,看着不协调。
谁有没有好的方法?

解决方案 »

  1.   

    http://blog.csdn.net/slyzly/archive/2010/04/05/5450751.aspx
      

  2.   

    Anchor
    设置为上下左右都停靠。随着窗体的变化而变化。
      

  3.   

    可以采用Form_Resize()。这种方法最灵活,思路是窗体变化时,直接重写这个变化函数。public Form1()
            {
                InitializeComponent();
                int count = this.Controls.Count * 2+2;
                float[] factor = new float[count];
                int i = 0;
                factor[i++] = Size.Width;
                factor[i++] = Size.Height;
                foreach(Control ctrl in this.Controls)
                {
                    factor[i++] = ctrl.Location.X / (float)Size.Width;
                    factor[i++] = ctrl.Location.Y / (float)Size.Height;
                    ctrl.Tag = ctrl.Size;
                }
                Tag = factor;
            }        private void Form1_Resize(object sender, EventArgs e)
            {
                float[] scale = (float[])Tag;
                int i = 2;            foreach (Control ctrl in this.Controls)
                {
                    ctrl.Left = (int)(Size.Width * scale[i++]);
                    ctrl.Top = (int)(Size.Height * scale[i++]);
                    ctrl.Width = (int)(Size.Width / (float)scale[0] * ((Size)ctrl.Tag).Width);
                    ctrl.Height = (int)(Size.Height / (float)scale[1] * ((Size)ctrl.Tag).Height);                  //每次使用的都是最初始的控件大小,保证准确无误。
                }
            }
      

  4.   

    Anchor
    Dock多使用容器控件。