简体   繁体   中英

Bringing panel to front on a click of a button in c#

I would like some help with code so my panels get brought to front when I click a button.

I have tried

private void button22_Click(object sender, EventArgs e)
{
    panel4.BringToFront();
}

but that didn't seem to work for me. Does anyone know what I'm doing wrong or how I could get this working? I am in c# winforms.

That should work fine. You code says panel4 so I assume you have multiple panels.

If you have placed panel3 on panel4 , then BringToFront() will bring both forward and may look like there is no change. Make sure both panels have the form as their parent. You can do this by cut and paste, or making sure that you click the form canvas (not an existing panel) when you add the other panels.

The same for buttons, textboxes etc, if you draw them on to a panel, they will stay as is on that panel when you bring them forwards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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