NotifyIcon system tray will not accept left click event

I am creating a System-Tray application. It was difficult to have an icon without a main form, but on previous topics in StackOverflow I worked it out. Right click works fine, I'm connected in the context menu, etc.

I am having problems left-clicking. As far as I can tell, the "notifyIcon1_Click" event doesn't fire at all.

    private void notifyIcon1_Click(object sender, EventArgs e)
    {
        Debug.WriteLine("Does it work here?");

        if (e.Equals(MouseButtons.Left))
        {
            Debug.WriteLine("It worked!");
        }
    }

None of these debugging lines are output, breakpoints in this event do not stop the program, etc.

Am I doing it wrong? What should be my next step? I am coding this in C # using Windows 7, if that matters at all for the behavior of the taskbar.

+3
source share
3

, MouseClick , MouseClick, .

, , :

private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
    if(e.Button == MouseButtons.Left)
        //Do the awesome left clickness
    else if (e.Button == MouseButtons.Right)
        //Do the wickedy right clickness
    else
        //Some other button from the enum :)
}
+7

, click /

_notifyIcon.BalloonTipClicked += notifyIconBalloon_Click;


private void notifyIconBalloon_Click(object sender, EventArgs e)
{
// your code
}
0

Another answer is not clear that you need a MouseClick event instead of a Click.

notifyIcon.MouseClick += MyClickHandler;

Then your handler function will work fine.

void MyClickHandler(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        Console.WriteLine("Left click!");
    }
}
-1
source

Source: https://habr.com/ru/post/1728108/


All Articles