Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one get a ContextMenuStrip to show on left click of a NotifyIcon?

I have a ContextMenuStrip assigned to a NotifyIcon and this works with the right click fine.

How may I wire up the mouse-click event to tell the NotifyIcon 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;
    }
}
like image 859
hydrogen Avatar asked Oct 14 '25 08:10

hydrogen


1 Answers

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's a good thread about the subject at MSDN site.

like image 150
Mikael Koskinen Avatar answered Oct 16 '25 22:10

Mikael Koskinen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!