简体   繁体   English

双击NotifyIcon时如何聚焦窗口

[英]How to focus my window when I double-click on NotifyIcon

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? 有任何想法吗?

BringToFront() doesn't do what you hope it does, it only arranges windows owned by the same application. BringToFront()没有按照你的希望做它,它只安排同一个应用程序拥有的窗口。 To get in front of windows owned by other applications you need to use Activate() instead. 要进入其他应用程序拥有的Windows,您需要使用Activate()。 Which often fails, you can't steal the focus away, but not a problem when you click on a NotifyIcon you own. 经常失败的是,当你点击你拥有的NotifyIcon时,你不能偷走焦点,但不会出现问题。 Fix: 固定:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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