在 Form1 中放一个 panel ,问一下,当Form1 窗口变大,或是最大化的时候 ,panel 始终大小不变,而且始终显示在窗口的中央?要设置哪几个参数?

解决方案 »

  1.   

    在Form的OnResize事件中,自己写代码控制panle的位置
      

  2.   

    把pannel的Anchor属性设为(top,left,right,bottom)即可
      

  3.   


    按上面设置后,pannel的大小也会跟着变化,我是想实现这样:当Form1 窗口变大,或是最大化的时候 ,panel 始终大小不变,而且始终显示在窗口的中央?
      

  4.   

    自己算一下就好了,比如一个窗体Form1中有个Panel1,
    不管窗体怎么变化,Panel1的左上角的那个点都在窗体中心,
    你将Panel1的中心点和Panel1的左上角对比就可以算出来        private void Form1_Resize(object sender, EventArgs e)
            {
                this.panel1.Location = new Point(this.Width/2, this.Height/2);     
            }
      

  5.   


    在OnResize事件中添加:
    this.pannel.top=(this.heigh-this.pannel.heigh)/2;
    this.pannel.left=(this.width-this.pannel.width)/2
      

  6.   

    把pannel的Anchor属性设为top,left然后在Form1的OnResize 事件中添加如下代码
    this.panel.Top=(this.Height-this.panel.Height)/2;
    this.panel.Left=(this.Width-this.panel.Width)/2;