怎么使控件的宽度随窗体宽度的变化而变化?

解决方案 »

  1.   

    点控件,属性, 确保设置Anchor里面有Left和Right
      

  2.   

    private void Form1_Load(object sender, EventArgs e)
            {
                this.Tag = this.Width.ToString() + "," + this.Height.ToString();
                this.SizeChanged += new EventHandler(Form1_Resize);
            }
            private void Form1_Resize(object sender, EventArgs e)
            {
                //this.tableLayoutPanel1.Height = this.Height;
               // this.tableLayoutPanel1.Width = this.Width;
                //ResizeInit(this);
                
                //MessageBox.Show(this.Width.ToString() + "," + this.Height.ToString());
                string[] 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));            }        }
    控件随窗体变化变化大小
      

  3.   

    在form的resize事件里面写
    不可能每个控件都改动  只有个别几个控件需要改
    直接写
    如:
    TextBox1.Height=this.Height-100;
    TextBox1.Width=this.Width-200;
    如此这般
      

  4.   

    加个splitContainer控件,把你的控件放到里面,设置要变大的控件的Dock属性为Fill,然后将要变大的控件的Anchor属性改为Top, Bottom, Left, Right ;就OK了