【问题标题】:Hide dummy taskbar icon for notification icon context menu隐藏通知图标上下文菜单的虚拟任务栏图标
【发布时间】:2021-11-16 17:09:48
【问题描述】:

我有一个简单的 .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 属性)显示上下文菜单条,则不会发生这种情况。

如何防止出现此图标?

【问题讨论】:

  • 你说的是ShowInTaskbar属性吗?
  • 根本没有(将其更改为 false 并没有解决问题)。
  • 不要使用表单。将您的 NotifyIcon 存放在 ApplicationContext 派生类中,并在 Application.Run() 中运行它,而不是在 program.cs 中的 Form 中运行。

标签: c# notifyicon contextmenustrip


【解决方案1】:

我自己终于找到了解决办法:

[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);
}

【讨论】:

    【解决方案2】:

    试试 Me.Hide()

    让我们看看结果

    尝试将上下文菜单分配给 notifyicons .ContextMenu property like and use the notifyicons .Visible 属性以显示它,而不是使用 .Show 方法。

    【讨论】:

    • 这不会改变任何东西,因为表单已经不可见了。
    猜你喜欢
    • 1970-01-01
    • 2014-06-12
    • 1970-01-01
    • 2020-09-23
    • 2013-11-05
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多