How can I get ContextMenuStrip to show NotifyIcon with the left mouse button?

I have a ContextMenuStrip assigned by NotifyIcon and this works with a right click.

How can I hook a mouse event to tell NotifyIcon how to show its ContextMenuStrip?

private void taskbarIcon_MouseClick(object sender, MouseEventArgs e)
{
    switch (e.Button)
    {
        case MouseButtons.Left:
            // What could I use here?
            break;
        default:
            break;
    }
}
+3
source share
1 answer

You should be able to use the following code:

if (e.Button == MouseButtons.Left)
{
   MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", 
            BindingFlags.Instance |BindingFlags.NonPublic);
    mi.Invoke(taskbarIcon, null);
}

Here is a good thread about the subject on MSDN.

+9
source

Source: https://habr.com/ru/post/1761852/


All Articles