简体   繁体   English

执行某些操作后显示通知图标上下文菜单

[英]Show notification icon context menu after performing some action

I need to show the context menu for my notification icon context menu for both left and right clicks after performing some actions rather than right after the click. 我需要在执行某些操作后而不是单击后立即在左右单击中显示通知图标上下文菜单的上下文菜单。

It works perfectly for the left-click as: 它非常适合于左键单击,如下所示:

sysTrayIcon.MouseClick += OnSysTrayClicked;

private static void OnSysTrayClicked(Object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        PerformActions();
        MethodInfo oMethodInfo = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
        oMethodInfo.Invoke(sysTrayIcon, null);
    }
}

But the right-click is still handled automatically and the associated ContextMenuStrip is shown at the right-click. 但是,右键单击仍会自动处理,并且右键单击时会显示关联的ContextMenuStrip Is there some way to override that with my event handler? 有什么方法可以用我的事件处理程序覆盖它吗?

There are two options. 有两种选择。

Option A: Do not assign the context menu to this.ContextMenuStrip. 选项A:不要将上下文菜单分配给this.ContextMenuStrip。 Open the context menu manually whenever you want to. 您可以随时手动打开上下文菜单。 Be aware, that strip.Top and strip.Left must be absolute screen coordinates. 请注意,strip.Top和strip.Left必须是屏幕的绝对坐标。

Option B: De-assign this.ContextMenuStrip OnMouseDown if right-mouse-button and re-assign OnMouseUp. 选项B:如果鼠标右键单击,则取消分配this.ContextMenuStrip OnMouseDown,然后重新分配OnMouseUp。 See this example . 请参阅此示例

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

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