我试过很多东西,但都没有用...
我有一个表单,在单击 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 block 的末尾。
最后,我发现当我在 NotifyIcon 上单击鼠标右键并打开上下文菜单时这不起作用时,我可以左键单击 NotifyIcon 并将它带到前面。
我尝试在开头添加这段代码:
cmsNotifyIcon.Show();
cmsNotifyIcon.Close();
因此它显示并关闭 notifyIcon 上下文菜单,作为一种可能的解决方法,但它没有帮助。
关于如何执行此操作或解决此问题的任何想法?
最佳答案
如果您在 MouseUp 上执行怎么办?
关于c# - 无法始终如一地将表格放在首位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2013849/