79417509

Date: 2025-02-06 10:25:15
Score: 2
Natty:
Report link

Quite a while ago..., but I stumbled over the same problem - many people seem to have the same problem, but there was no proper solution.
Finally I found this and it solved it! ContextMenuStrip from a left click on a Notify Icon

In short: the default right-click p/invokes SetForgroundWindow before showing the menu.

So adding this to Your code will make it behave like it does when performing a right-click:

[DllImport("User32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern bool SetForegroundWindow(HandleRef hWnd);

private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        SetForegroundWindow(new HandleRef(this, this.Handle));
        this.contextMenuStrip1.Show(this, this.PointToClient(Cursor.Position));
    }
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): have the same problem
  • Low reputation (0.5):
Posted by: Stephan