Keep Control always on top

BudBrot picture BudBrot · Apr 16, 2013 · Viewed 13.2k times · Source

Is it possible to keep a control (Panel) always over all other controls even if they also use Control.BringToFront()?

I tired to use BringToFront itself, but it seems that this loose its effectiveness if another control under this control also uses this command.

Answer

Martin Prikryl picture Martin Prikryl · Apr 16, 2013

It would help if you try to explain what are you trying to achieve. We might be then able to better convince you, that you are doing something very wrong :)

Anyway, no matter what trick you do, the other control may use the same trick to override you.

You can get step ahead for example by handling parent control's Layout event to force your control back to front. The Layout event is trigerred (among other) when child controls' Z-order is changed.

private void Form1_Layout(object sender, LayoutEventArgs e)
{
    panel1.BringToFront();
}