views:

842

answers:

3

How do i force a context menu for a tray icon to be shown when it is click rather than just right-clicked.

Ive tried using the MouseClick event, but the eventargs have the mouse position at x0y0.

+5  A: 

This should do it for you:

private void notifyIcon1_Click(object sender, EventArgs e)
        {
            contextMenuStrip1.Show(Cursor.Position.X, Cursor.Position.Y);
        }
Jason Heine
Also, if you need to move the content around you could always do X +/- 10 or something
Jason Heine
A: 

That works, but it's not quite the same. When I open the menu that way, a button is created on the task bar, and clicking off of the menu does not clear it. Both Vista and XP exhibit this behavior

rotard
A: 

An alternate method that I have found to work a bit better:

private void notifyIcon1_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            System.Reflection.MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            mi.Invoke(notifyIcon1, null);
        }
    }
rotard