强制 Windows 显示系统托盘图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/958817/
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
Force Windows to show a system tray icon
提问by Andrew Ensley
This is a pretty stupid question, but here goes:
这是一个非常愚蠢的问题,但这里有:
Is there a way (in .net) to force Windows to show your system tray icon instead of hiding it? I don't want to do this all the time, but at least for the first time my application is run I would like it to be visible in the system tray.
有没有办法(在 .net 中)强制 Windows 显示您的系统托盘图标而不是隐藏它?我不想一直这样做,但至少在我的应用程序第一次运行时,我希望它在系统托盘中可见。
回答by Joe White
As Raymond Chen would say, "Imagine if this were possible." Now tell me how many apps would choose notto force their tray icon to be always visible! Everybody thinks their tray icon is the most important. If there was a programmatic way to say "show my tray icon all the time", we'd be back to Windows 95.
正如 Raymond Chen 所说,“想象一下这是否可能。” 现在告诉我有多少应用程序会选择不强制其托盘图标始终可见!每个人都认为他们的托盘图标是最重要的。如果有一种编程方式可以说“一直显示我的托盘图标”,我们会回到 Windows 95。
Configuration of tray-icon hiding is left to the user, on purpose. If you want to always see your tray icon on your computer, there's nothing stopping you. Just right-click on the expander button, click "Customize Notification Icons" (that's what it's called in Vista, may vary in other OS versions), find your app's tray icon in the list, and select "Show".
托盘图标隐藏的配置是故意留给用户的。如果您想始终在计算机上看到您的托盘图标,没有什么可以阻止您。只需右键单击扩展按钮,单击“自定义通知图标”(在 Vista 中就是这样称呼的,在其他操作系统版本中可能会有所不同),在列表中找到您应用的托盘图标,然后选择“显示”。
回答by maranas
it does not show because, even if you uninstall your application, the display setting is saved under the PastIconsStream registry entry. Windows saves the settings for icon identifiers even if the app isn't already installed. For the first install, it will appear, then hide itself (which is what you want to achieve, I think). For subsequent installs, it won't appear anymore, because Windows remembers the setting. If you are still testing your application, try clearing the PastIconsStream registry entry. This will revert back to the "show at first, then hide" behavior.
它不会显示,因为即使您卸载应用程序,显示设置也会保存在 PastIconsStream 注册表项下。即使尚未安装该应用程序,Windows 也会保存图标标识符的设置。对于第一次安装,它会出现,然后隐藏自己(我认为这是您想要实现的)。对于后续安装,它将不再出现,因为 Windows 会记住该设置。如果您仍在测试您的应用程序,请尝试清除 PastIconsStream 注册表项。这将恢复到“首先显示,然后隐藏”行为。
回答by 1800 INFORMATION
The first time your tray icon is shown, it will be made visible, at least for a short time. The rest is left up to the user - if they want to hide it then you should really respect that decision.
第一次显示您的托盘图标时,它至少会在短时间内可见。剩下的由用户决定 - 如果他们想隐藏它,那么您应该真正尊重该决定。
回答by Jon Grant
There is no way to force it to be visible (as noted above, and rightly so), however if you show a balloon notification (like Windows Live Messenger does when you first try to close the window), your icon will appear while the balloon is visible. You could also use this to draw attention to your app to say "look at me, I'm down here!".
没有办法强制它可见(如上所述,这是正确的),但是如果您显示气球通知(就像 Windows Live Messenger 在您第一次尝试关闭窗口时所做的那样),您的图标将在气球出现时出现是可见的。你也可以用它来吸引对你的应用程序的注意,说“看着我,我在这里!”。
Please, for the sake of your users, make it only do this once, at most, though!
不过,为了您的用户,请让它最多只执行一次!