[英]Hide dummy taskbar icon for notification icon context menu
我有一个简单的 .Net 5.0 WinForm 表单,它在应用程序启动后自动隐藏:
private void form_Shown (object sender, EventArgs e)
{
Hide ();
}
它只创建一个通知图标。 此通知图标具有由单击鼠标左键所示的上下文菜单条:
private void notifyIcon_Click (object sender, EventArgs e)
{
contextMenuStrip.Show (MousePosition);
}
这工作正常,但只要上下文菜单条可见,就会出现一个虚拟任务栏图标:
如果表单未隐藏或右键单击(通过 ContextMenuStrip 属性)显示上下文菜单条,则不会发生这种情况。
如何防止出现此图标?
我终于自己找到了解决方案:
[DllImport ("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern bool SetForegroundWindow (HandleRef hWnd);
private void notifyIcon_Click (object sender, EventArgs e)
{
SetForegroundWindow (new HandleRef (notifyIcon.ContextMenuStrip, notifyIcon.ContextMenuStrip.Handle));
notifyIcon.ContextMenuStrip.Show (MousePosition);
}
试试我。隐藏()
让我们看看结果
尝试将您的上下文菜单分配给 notifyicon s .ContextMenu property like and use the notifyicon
.ContextMenu s .ContextMenu property like and use the notifyicon
s .Visible 属性来显示它,而不是使用 .Show 方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.