最小化托盘 C# WinForms 应用程序的正确方法是什么? [英] What's the proper way to minimize to tray a C# WinForms app?

查看:27
本文介绍了最小化托盘 C# WinForms 应用程序的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 WinForms 应用程序最小化到系统托盘的正确方法是什么?

What is the proper way to minimize a WinForms app to the system tray?

注意:最小化到系统托盘;在时钟的任务栏右侧.我不是在问最小化到任务栏,这是当您点击窗口上的减号"按钮时发生的情况.

Note: minimize to system tray; on the right side of the taskbar by the clock. I'm not asking about minimizing to taskbar, which is what happens when you hit the "minus" button on the window.

我见过一些骇人听闻的解决方案,例如最小化,设置 ShowInTaskbar = false,然后显示您的 NotifyIcon."

I've seen hackish solutions like, "minimize, set ShowInTaskbar = false, then show your NotifyIcon."

像这样的解决方案是骇人听闻的,因为该应用程序似乎不像其他应用程序那样最小化到托盘,代码必须检测何时设置 ShowInTaskbar = true,以及其他问题.

Solutions like that are hackish because the app doesn't appear to minimize to the tray like other apps, the code has to detect when to set ShowInTaskbar = true, among other issues.

这样做的正确方法是什么?

What's the proper way to do this?

推荐答案

实际上没有管理的方法可以在本机 winforms 中对托盘执行这种形式的动画,但是您可以 P/Invoke shell32.dll 来做到这一点:

There is actually no managed way to do that form of animation to the tray in native winforms, however you can P/Invoke shell32.dll to do it:

这里有一些不错的信息(在评论而不是帖子中):

Some good info here (In the comments not the post):

http://blogs.msdn.com/jfoscoding/存档/2005/10/20/483300.aspx

这里是 C++:

http://www.codeproject.com/KB/shell/minimizetotray.aspx

您可以使用它来确定要为您的 C# 版本 Pinvoke 的内容.

You can use that to figure out what stuff to Pinvoke for your C# version.

这篇关于最小化托盘 C# WinForms 应用程序的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆