Question

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;
    }
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top