Bring a form to the front

  • Thread starter Thread starter Alistair George
  • Start date Start date
A

Alistair George

Having a bit of a battle here with getting a form on instantiation to
the front. EG the user would think that it was not running because the
window is hidden behind eg explorer. This works:

private void frmMain_Shown(object sender, EventArgs e)
{
// Make this form the active form and make it TopMost
this.ShowInTaskbar = false;
this.TopMost = true;
this.Focus();
this.BringToFront();
}
But, it leaves the window permanently in front of all windows. In
delphi, we say bringtofront, and it does just that, but in C#
bringtofront seems a bit flakey, and topmost is too invasive.
Thanks. Al.
 
Having a bit of a battle here with getting a form on instantiation to
the front. EG the user would think that it was not running because the
window is hidden behind eg explorer. This works:

private void frmMain_Shown(object sender, EventArgs e)
{
// Make this form the active form and make it TopMost
this.ShowInTaskbar = false;
this.TopMost = true;
this.Focus();
this.BringToFront();
}
But, it leaves the window permanently in front of all windows. In
delphi, we say bringtofront, and it does just that, but in C#
bringtofront seems a bit flakey, and topmost is too invasive.
Thanks. Al.

Why not just re-set TopMost back to false after the .BringToFront?
 
Why not just re-set TopMost back to false after the .BringToFront?
Yes, works cheers:
private void frmMain_Shown(object sender, EventArgs e)
{
// Make this form the active form and make it TopMost
this.ShowInTaskbar = false;
this.TopMost = true;
this.Focus();
this.BringToFront();
this.TopMost = false;
}
 
Back
Top