Question

When I double-click on my application icon like this, I want to get focus on the application. I've tried this:

private void noi_MouseDoubleClick(object sender, MouseEventArgs e)
{
    BringToFront();
    Focus();
}

But somehow it doesn't work. Any ideas?

Était-ce utile?

La solution

BringToFront() doesn't do what you hope it does, it only arranges windows owned by the same application. To get in front of windows owned by other applications you need to use Activate() instead. Which often fails, you can't steal the focus away, but not a problem when you click on a NotifyIcon you own. Fix:

private void noi_MouseDoubleClick(object sender, MouseEventArgs e)
{
    Activate();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top