通知图标气球提示未在 C# 中显示?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11284997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Notify Icon Ballon Tip Not showing in C#?
提问by Hunter Mitchell
i am using this code under my form1_load
我在我的 form1_load 下使用此代码
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(5000, "Welcome", "Hello " + User, ToolTipIcon.Info);
I even checked my registery and the value was 1. Why is the baloon not showing? I do have a icon form my notify icon. and it is showing up. The Baloon is not though!
我什至检查了我的注册表,值是 1。为什么气球不显示?我确实有一个图标形式我的通知图标。它正在出现。气球不是!
采纳答案by Metro Smurf
You may need to post the rest of the code that's in your form's load event, but here's a couple of suggestions:
您可能需要发布表单加载事件中的其余代码,但这里有一些建议:
- Make sure the form's Load event is actually hooked up.
- Make sure you've assigned an icon for the notify icon.
- 确保表单的 Load 事件实际上已连接。
- 确保您已为通知图标指定了一个图标。
Also, note that the balloon tip isn't guaranteed to show. See the Remarks section on msdn's NotifyIcon.ShowBalloonTip Methodarticle:
另外,请注意,气球提示不能保证显示。请参阅 msdn 的NotifyIcon.ShowBalloonTip 方法文章的备注部分:
Remarks
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.Only one balloon tip can display on the taskbar at a time. Attempting to display a balloon tip when one is currently displayed on the taskbar causes the timeout value to be ignored. The behavior is slightly different depending on the operating system and whether the balloon tip is from another, or the same, application. When the second balloon tip is from another application, the first balloon tip will display for the minimum timeout value before the second appears, regardless of the value of timeout. In most cases, if the balloon tips are from the same application, the first balloon tip immediately closes when another call to the ShowBalloonTip method is made. In some cases the second balloon will open on top of the first balloon.
The title text will display in a bold font near the top of the balloon.
备注
最小和最大超时值由操作系统强制执行,通常分别为 10 秒和 30 秒,但是这可能因操作系统而异。过大或过小的超时值将调整为适当的最小值或最大值。此外,如果用户似乎没有使用计算机(没有发生键盘或鼠标事件),那么系统不会将此时间计入超时。一次只能在任务栏上显示一个气球提示。尝试在任务栏上当前显示气球提示时显示气球提示会导致超时值被忽略。根据操作系统以及气球提示是否来自另一个或相同的应用程序,行为略有不同。当第二个气球提示来自另一个应用程序时,第一个气球提示将在第二个出现之前显示最小超时值,而不管超时值如何。在大多数情况下,如果气球提示来自同一个应用程序,当再次调用 ShowBalloonTip 方法时,第一个气球提示会立即关闭。在某些情况下,第二个气球会在第一个气球的顶部打开。
标题文本将在气球顶部附近以粗体显示。
回答by Kevin Aenmey
Here is some sample code for what @MetroSmurf has already mentioned. Note that this.InitializeComponent();must be called before the NotifyIconis shown (usually in the form constructor).
这是@MetroSmurf 已经提到的一些示例代码。注意this.InitializeComponent();必须在NotifyIcon显示之前调用(通常在表单构造函数中)。
public Form1()
{
this.InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
notifyIcon1.Icon = new Icon(@"C:\SomePath\MyIcon.ico");
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(5000, "Welcome", "Hello " + User, ToolTipIcon.Info);
}
Also ensure that windows is configured to allow notifications. In Windows 7 right-click taskbar, click Properties, Customize...in the notification area, tick the Always show all icons and notifications on the taskbaroption, click OK.
还要确保将 Windows 配置为允许通知。在 Windows 7 中右键单击任务栏,在通知区域中单击属性、自定义...,勾选始终在任务栏上显示所有图标和通知选项,单击确定。
回答by HatSoft
Looks like you forgot to set the Icon for it like this
看起来你忘了像这样设置图标
notifyIcon1.Icon = SystemIcons.Exclamation;
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(5000, "Welcome", "Hello " + User, ToolTipIcon.Info);
Also please read for more inormation on issues with NI http://www.csharp411.com/notifyiconshowballoontip-issues/
另请阅读有关 NI 问题的更多信息http://www.csharp411.com/notifyiconshowballoontip-issues/

