Bring a form to the front

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.
 
Z

zacks

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?
 
A

Alistair George

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top