can't perform middle click on a NotifyIcon

ms account 20 Reputation points
2023-09-15T14:55:33.7366667+00:00

Hello. The problem is when the middle mouse has been clicked on the tray the program always sees it like the left one has been. Creating a new notifyIcon control gives the same result. There is the same problem in other projects. Middle click is normally detected in other cases (clicking on a picturebox).

        private void notifyIcon_Tray_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left) f_ShowMainWindow();
            if (e.Button == MouseButtons.Middle) Objects_and_Functions.f_OpenDraft();
        }
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,891 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 45,266 Reputation points Microsoft Vendor
    2023-09-18T04:09:56.5333333+00:00

    Hi @ms account , Welcome to Microsoft Q&A,

    After testing with the following code in Windows 10/11:

       private void notifyIcon1_MouseDown(object sender, MouseEventArgs e)
       {
           MessageBox.Show(e.Button.ToString());
       }
    

    In Windows 11, notifyIcon1_MouseDown seems to recognize the middle mouse button as the left button. I tested this function normally in Windows 11.

    It seems that you can do what you want by building a global hook, but that is very troublesome and unsafe. If there are no special needs, I suggest you use other methods (such as left click and right click, single click and double click, you have four combinations to use)

    Waiting for your reply.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.