5

I have a NotifyIcon in my program which displays a baloon tip in the taskbar. I wrote code as

notifyIcon1.Icon = new Icon(SystemIcons.Application, 40, 40);
notifyIcon1.Visible = true;
notifyIcon1.Text = "Test Notify Icon Demo";
notifyIcon1.BalloonTipText =count+ " Alerts";
notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
notifyIcon1.BalloonTipTitle = "Alert!";
notifyIcon1.ShowBalloonTip(999999999);

The baloon tip is invisible after the set time (999999999). But I want to show the baloon tip until it is clicked as I have baloontipclicked event.

How to make baloontip visible forever?

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
sushma
  • 333
  • 1
  • 4
  • 13
  • 1
    Possible duplicate of http://stackoverflow.com/questions/2920029/c-notifyicon-showballoontip-timeout. Can't be done. Default Windows behavior to fade after a certain timeout if the user is active (keyboard and mouse activity -> http://msdn.microsoft.com/en-us/library/ms160064.aspx) – Christophe Geers Sep 17 '11 at 07:48
  • 1
    The shell has enforces rules about this. The timeout doesn't start ticking until it has some indication that the user *might* have seen it and it can't be made too long. If you want a permanent notification then you should not use a balloon tip. A regular topmost form is best, otherwise without guarantee that it can compete with other topmost windows. – Hans Passant Sep 17 '11 at 14:49

2 Answers2

7

You can show it again if it hasn't been clicked. You have the close event (BalloonTipClosed), if user hasn't ckicked it just show it again.

private void ShowBalloonTip(int minutes) {
    notifyIcon.BalloonTipIcon = ToolTipIcon.Error;
    notifyIcon.BalloonTipText = "Text";
    notifyIcon.BalloonTipTitle = "Title";
    notifyIcon.ShowBalloonTip(minutes* 60 * 1000);
    m_showUntil = DateTime.Now.AddMinutes(minutes);
}


private void notifyIcon_BalloonTipClosed(object sender, EventArgs e) {
    if (m_showUntil > DateTime.Now)
        notifyIcon.ShowBalloonTip(60 * 1000);
}
private void notifyIcon_BalloonTipClicked(object sender, EventArgs e) {
    m_showUntil = DateTime.MinValue;
    (..)
}
Kalay
  • 71
  • 1
  • 2
  • Just a minor issue. If another notification comes when this is on then it puts the application in not responding state. Ones who thinks about applying this snippet to their code should edit it to limit as only one notification at the same time. – Baz Guvenkaya Oct 26 '14 at 23:05
7

from MSDN:

Minimum and maximum timeout values are enforced by the operating system and are typically 10 and 30 seconds, respectively, however this can vary depending on the operating system. Timeout values that are too large or too small are adjusted to the appropriate minimum or maximum value. In addition, if the user does not appear to be using the computer (no keyboard or mouse events are occurring) then the system does not count this time towards the timeout.

it seems not be possible to override the maximum timeout (eventually adjusted by Windows and limited to 30 seconds even if you specify a longer one) so the Notification will fade away, will not wait for you to click on it after 2 minutes.

if you want to really have a different behavior you should probably use something else, other objects or simulate something similar with forms where you have the full control on the behavior and you can show, hide and close as you wish from your code.

Davide Piras
  • 43,984
  • 10
  • 98
  • 147