Search code examples
c#winformsdouble-clicknotifyiconballoon

C#, Windows Forms: NotifyIcon with ShowBalloonTip in Click event no longer fires the DoubleClick event


When using a NotifyIcon in Windows Forms/C#/.Net Framework 2.0, if I display a Balloon Tip Text in the MouseClick or Click events, none of the DoubleClick or MouseDoubleClick events will fire:

    private void notifyIcon_DoubleClick(object sender, EventArgs e)
    {
        MessageBox.Show("double click"); // this is never called on double-click
    }

    private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        MessageBox.Show("mouse double click"); // this is never called on double-click
    }

    private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            this.notifyIcon.BalloonTipText = "Some Info";
            this.notifyIcon.ShowBalloonTip(1000);
        }
    }

If I double-click the notify icon, I get the Balloon Tip showed/refresh twice, but no message box.

I'm using Visual Studio 2010 and Windows 7 Ultimate 64-bit.

Thanks in advance for any help!


Solution

  • You need to check if it's a double click in you notifyIcon_MouseClick

     private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left) 
            {
              if (e.Clicks < 2) //not a doubleclick
              {
                  this.notifyIcon.BalloonTipText = "Some Info";
                  this.notifyIcon.ShowBalloonTip(1000);
              }
            }
        }