如果两个panel重合在一起,点击不同按钮切换显示不同的panel,需要xxx.BringToFront();

1、首先让两个panel的visible都为false,

在加载页面load方法里可以让一个panel先显示出来

    private void Ceshi1_Load(object sender, EventArgs e)
        {
            this.panel1.Visible = true;
        }

 

切换

private void button1_Click(object sender, EventArgs e)
    {
        
        this.panel1.Visible = true;
        this.panel2.Visible = false;
    }

    private void button2_Click(object sender, EventArgs e)
    {
        this.panel2.Visible = true;
        this.panel1.Visible = false;
        this.panel2.BringToFront();
    }

 

 

2、有时候把panel2直接用鼠标拖到panel1上,会使两个panel融合在一起,

可以将panel2放在一个空白地方,点击按钮切换时,让位置相等即可

 

    private void button2_Click(object sender, EventArgs e)
    {
        this.panel2.Visible = true;
        this.panel1.Visible = false;
        this.panel2.BringToFront();
     panel1.Location = panel2.Location;//让位置相等 }

 

 

参考:

http://bbs.csdn.net/topics/390741533

 posted on 2016-11-04 17:55  布鲁布鲁sky  阅读(10470)  评论(0编辑  收藏  举报