简体   繁体   English

将面板放在C#的前面

[英]Bringing panels to the front in C#

For some reason when I use code such as 由于某些原因,当我使用诸如

this.panel.BringToFront(); this.panel.show(); this.panel.visible = true

And I set the other panels to false, etc. 我将其他面板设置为false,等等。

Current Code which shows the bottom panel 3 but blanks out for panel 4 and 5. 当前代码显示底部面板3,但对面板4和5保留空白。

private void button10_Click(object sender, EventArgs e)
    {

        this.panel3.Location = this.panel3.Location;
        this.panel3.Show();
        this.panel3.BringToFront();

        this.panel4.SendToBack();
        this.panel4.Hide();
        this.panel5.SendToBack();
        this.panel5.Hide();




    }


private void button4_Click(object sender, EventArgs e)
    {
        this.panel5.Location = this.panel5.Location;
        this.panel5.Show();
        this.panel5.BringToFront();

        this.panel4.SendToBack();
        this.panel4.Hide();
        this.panel3.SendToBack();
        this.panel3.Hide();




    }

private void button3_Click(object sender, EventArgs e)
    {
        this.panel4.Location = this.panel4.Location;
        this.panel4.Show();
        this.panel4.BringToFront();

        this.panel5.SendToBack();
        this.panel5.Hide();
        this.panel3.SendToBack();
        this.panel3.Hide();


    }

This doesnt work tho and when I click button3 and button 4 it displays none of the panels and when I click on button10 it displays panel3(the bottom panel) which it is supposed to but why doesn't it display panels 4 and 5. 这不起作用,当我单击button3和button 4时,它不显示任何面板,而当我单击button10时,它应显示应该显示的panel3(底部面板),但是为什么不显示面板4和5。

I have also made the buttons do this and it has the same error: 我也使按钮执行此操作,并且它具有相同的错误:

 private void button4_Click(object sender, EventArgs e)
    {
        panel5.Visible = true;
        panel4.Visible = false;
        panel3.Visible = false;




    }

But this also doesn't work. 但这也不起作用。 I have asked some people on discord but no one seems to know anything these days and just get roles for free which is stupid but ye that's why I am here asking for help. 我问过一些不和谐的人,但这些天似乎没人知道什么,只是免费获得角色是愚蠢的,但这就是为什么我在这里寻求帮助。

When you add panels on other panels, It goes inside the first panel. 在其他面板上添加面板时,它将进入第一个面板。 When you try panel.BringToFront() it does not work because the first panel is in the back. 当您尝试使用panel.BringToFront()它不起作用,因为第一个面板在背面。

Here is what you can do... 这是您可以做的...

Go to View -> Other Windows -> Document Outline 转到查看->其他Windows->文档大纲

在此处输入图片说明

Then try to get panels to the same level and move the panels using arrow keys instead of dragging using the mouse. 然后尝试将面板设置为相同的级别,并使用箭头键移动面板,而不是使用鼠标拖动面板。

It seems you have added the panels inside the other panel which you want to display. 似乎您已在要显示的其他面板中添加了面板。 Show it doesn't show the proper panel when you click the buttons. 单击按钮时,显示它不会显示正确的面板。

Ensure the parent of your panels should be same. 确保面板的父面板相同。 If the parent of your panels are different, then change the parent of the panels are same. 如果面板的父级不同,则更改面板的父级相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM