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?

4

2 回答 2

7

如果它没有被点击,你可以再次显示它。您有关闭事件(BalloonTipClosed),如果用户没有点击它,只需再次显示它。

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;
    (..)
}
于 2013-04-18T12:26:16.977 回答
7

来自 MSDN:

最小和最大超时值由操作系统强制执行,通常分别为 10 秒和 30 秒,但是这可能因操作系统而异。将太大或太小的超时值调整为适当的最小值或最大值。此外,如果用户似乎没有在使用计算机(没有发生键盘或鼠标事件),则系统不会将此时间计入超时。

似乎无法覆盖最大超时(最终由 Windows 调整并限制为 30 秒,即使您指定更长的时间),因此通知将消失,不会等待您在 2 分钟后单击它。

如果您真的想拥有不同的行为,您可能应该使用其他东西、其他对象或模拟与您可以完全控制行为的表单类似的东西,并且您可以根据您的代码显示、隐藏和关闭。

于 2011-09-17T12:32:17.547 回答