如图:在窗体上依次添加了这三个按钮,现在想实现“移到上层”、“移到下层”的功能。
将"button2"执行了"移到上层"命令后,"button2"就会在button1和button3之上(遮住了 button1和button3)。
将"button3"执行了"移到下层"命令后,"button3"会在button1之上、button2之下(处于中间,遮住了 button1,但又被button3遮住)。请各位给你思路或者实例代码,谢谢大家。

解决方案 »

  1.   

    control.BringToFront();
    control.SetToBack();
      

  2.   

    在designer设计页面里面,你可以找到:            this.Controls.Add(this.button3);
                this.Controls.Add(this.button2);
                this.Controls.Add(this.button1);
    这个add的先后顺序就是你在界面上看到的从外到里的顺序...
      

  3.   

    你可以通过程序来调整controls容器
      

  4.   


    基本原理
    this.Controls["button1"].BringToFront();
      

  5.   

    this.Controls["button1"].SendToBack();
      

  6.   

    control.BringToFront(); 
    control.SetToBack();这来个方法只能实现“移到最顶层”、“移到最底层”的功能啊,无法实现“上移一层”、“下移一层”
      

  7.   

            private void button2_Click(object sender, EventArgs e)
            {
                this.Controls.SetChildIndex(button2, 0);
            }        private void button3_Click(object sender, EventArgs e)
            {
                this.Controls.SetChildIndex(button3, 2);
            }SetChildIndex是设置显示的顺序。0是最前面。
      

  8.   

    想把一个控件放在某个Z序的某个位置,可以这样
            private void button1_Click(object sender, EventArgs e)
            {
                this.Controls.SetChildIndex(button1, (int)numericUpDown1.Value);
            }        private void button2_Click(object sender, EventArgs e)
            {
                this.Controls.SetChildIndex(button2, (int)numericUpDown1.Value);
            }        private void button3_Click(object sender, EventArgs e)
            {
                this.Controls.SetChildIndex(button3, (int)numericUpDown1.Value);
            }用一个numericUpDown来控制所在的层,这样可以方便你研究这一方法。