组合 NotifyIcon 和 ToolTip
我一直在使用 NotifyIcon 以便在任务栏中显示图标。 该程序没有 Windows 窗体。我也许可以创建一个并使其不可见,但我希望避免它。 NotifyIcon 附加的 ToolTip 功能有些缺乏,这里的一位专家建议我看看 ToolTip 功能。可以将工具提示附加到表单。是否可以将其附加到 NotifyIcon?我正在尝试这样做:
NotifyIcon CTicon = new NotifyIcon();
ToolTip toolTip = new ToolTip();
toolTip.SetToolTip(CTicon, "Test");
我收到错误“无法从‘System.Windows.Forms.NotifyIcon’转换为‘System.Windows.Forms.Control’。有没有办法转换?我也尝试过:
toolTip.SetToolTip(CTicon.Container, "Test");
但是一个容器显然也不是有效的控制。 对于我完全不了解这可能或可能不起作用的情况,我深表歉意。
提前致谢。
I have been working with NotifyIcon in order to show an icon in the taskbar.
This program has no Windows Form. I perhaps could create one and make it invisible but I was hoping to avoid it. The ToolTip functions attached to NotifyIcon are somewhat lacking, and one of the gurus here suggested I look at the ToolTip functionality. It is possible to attach ToolTip to a form. Is is possible to attach it to just the NotifyIcon? I'm trying do this:
NotifyIcon CTicon = new NotifyIcon();
ToolTip toolTip = new ToolTip();
toolTip.SetToolTip(CTicon, "Test");
And I get the error "cannot convert from 'System.Windows.Forms.NotifyIcon' to 'System.Windows.Forms.Control'. Is there a way to convert? I also tried:
toolTip.SetToolTip(CTicon.Container, "Test");
but a container is apparently not a valid control either.
I apologize for my total lack of understanding of how this may or may not work.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
一个迟来的答案,但可能对其他人有用。
A belated answer, but maybe useful for others .
托盘图标不支持方形工具提示,仅支持气球。有点道理,图标通常非常靠近,因此很难看出哪个图标产生了气球上没有“茎”的尖端。使用 NotifyIcon.BalloonTipText 属性。
Tray icons don't support square tool tips, only balloons. Kinda makes sense, the icons are usually quite close together so it would be hard to see what icon produced the tip without the "stem" on the balloon. Use the NotifyIcon.BalloonTipText property.
NotifyIcon 用于您在屏幕右下角看到的系统托盘图标,ToolTip 的使用仅适用于文本框、复选框等控件...例如,假设有一个名为 ' 的 TextBox 实例textBox1',在表单上比这有效:
现在,当您将鼠标悬停在文本框上时,会显示一个工具提示...
NotifyIcon is used for the system tray icon that you see on the bottom right hand corner of the screen, usage of ToolTip is only for controls such as textboxes, checkboxes and so on...for example, let's assume there's a TextBox instance called 'textBox1', on the form than this would work:
Now, when you mouse-over the textbox, a tooltip is shown...
我不确定您是否可以直接在通知图标上设置工具提示。这与在通知图标本身上设置文本属性是一样的。通知图标文本有一些限制。它的长度限制为 128 个字符,并且只会保留很短的时间。如果您想在更长的时间内显示更多信息,您应该查看通知图标的气球文本属性。我强烈建议您阅读 MSDN 页面,它非常有帮助。
http://msdn.microsoft.com/en-我们/library/system.windows.forms.notifyicon.aspx
I'm not sure you can set a tooltip directly on a notify icon. It's the same thing as setting the text property on the notify icon itself. There are some limitations to the notify icon text. It's limited to 128 chars and will only stay up for a short amount of time. If you want to display more info for a longer amount of time you should look at the balloon text property of the notify icon. I highly suggest reading the MSDN page it's quite helpful.
http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx
你不应该。
NotifyIcon 用于显示通知,而 ToolTip 用于显示有关用户当前活动的信息,它应该“就地”使用。
检查用户界面指南:
You shouldn't.
NotifyIcon is used to show notifications, whereas ToolTip is used to show the information about the user's current activity, it should be used "in place".
Check the user interface guidelines:
我计算机上的所有托盘图标都有工具提示。您需要使用接受 Component 作为参数的构造函数来创建 NotifyIcon。它显示 NotifyIcon.Text 属性。
我能够使用此处的示例代码创建一个:
http://msdn.microsoft.com/en-us/library/1by05f8d.aspx
All the tray icons on my computer have tooltips. You need to create your NotifyIcon using the constructor that accepts a Component as an argument. It displays the NotifyIcon.Text property.
I was able to create one using the example code here:
http://msdn.microsoft.com/en-us/library/1by05f8d.aspx