One click to open menu for tray icon in C #

How to configure the context menu to display the tray icon when it is clicked, and not just right-click.

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

+7
c # winforms contextmenu
source share
2 answers

This should do it for you:

private void notifyIcon1_Click(object sender, EventArgs e) { contextMenuStrip1.Show(Cursor.Position.X, Cursor.Position.Y); } 
+12
source share

The alternative method I found works a little 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); } } 
+8
source share

All Articles