views:

142

answers:

1

Hi, I'm creating a System-Tray only application. It's somewhat complicated to have the icon without a main form, but through previous topics on StackOverflow I've worked it out. The right-click works fine, I've linked in a context menu, etc.

I'm having problems with the left-click. As far as I can tell, the "notifyIcon1_Click" event isn't firing 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!");
        }
    }

Neither of those debug lines are outputting, breakpoints in that event don't stop the program, etc.

Am I doing this incorrectly? What should my next step be? I'm coding this in C#, using Windows 7 if that matters at all for taskbar behavior.

+1  A: 

If you want to determine if it's a left or right click, wire up the MouseClick, rather than click.

That way you get a signature like this:

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 :)
}
TreeUK
What would be the equivalent of "this.notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);" in this case? The obvious (that is, replacing "Click" with "MouseClick" throws a "No overload for 'notifyIcon1_MouseClick' matches delegate 'System.EventHandler'" error.Other than that, though, thanks! I was about to start on why I couldn't get left/right working, but you beat me to the punch.
cksubs
*edit, trying to get the codeblocks as used by the commenter above. But it didn't work. Wish comments had a fully featured text editor...
cksubs
Nevermind, got it! Thanks!
cksubs