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.
I've seen hackish solutions like, "minimize, set ShowInTaskbar = false, then show your NotifyIcon."
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?
Press Alt + F1 and that window will minimize to the tray.
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/archive/2005/10/20/483300.aspx
And here it is in C++:
http://www.codeproject.com/KB/shell/minimizetotray.aspx
You can use that to figure out what stuff to Pinvoke for your C# version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With