我尝试了几种方法,但没有一个起作用......
我的表单在单击 NotifyIcon 时应该出现在所有 Windows 的前面。所以这是我尝试过的:
private void notifyIcon1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.TopMost = true;
this.BringToFront();
this.Focus();
this.TopMost = false;
}
}
然后我尝试使用 SetForegroundWindow:
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool SetForegroundWindow(IntPtr hwnd);
通过增加
SetForegroundWindow(this.Handle);
在 if 块的末尾。
最后,我发现如果我在 NotifyIcon 上单击鼠标右键并打开上下文菜单,这不起作用,那么我可以左键单击 NotifyIcon 并将其带到前面。
我尝试在开头添加此代码:
cmsNotifyIcon.Show();
cmsNotifyIcon.Close();
这样它就会显示并关闭 notificationIcon 上下文菜单,作为解决方法的一个可能的想法,但它没有帮助。
关于如何做到这一点或解决这个问题有什么想法吗?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)