界面有一个panel  Dock已经Fill了panel 上有一个 textBox  怎么设置 才能让textBox 永远助于界面最中间?

解决方案 »

  1.   

    动态设置一下:control.Left = panel1.Width / 2;
                control.Top = panel1.Height / 2;
      

  2.   

    应该还要减去自身的:
    control.Left = (panel1.Width - control.Width) / 2;
    control.Top = (panel1.Height - control.Height) / 2;
      

  3.   


            private void Form2_Resize(object sender, EventArgs e)
            {
                textBox2.Top = (panel1.Height - textBox2.Height) / 2;
                textBox2.Left = (panel1.Width - textBox2.Width) / 2;
            }