Send to Tray Close

How can I send a minimized window to the tray when I click the close button? Also, how to show the tray icon when starting the application?

+7
c # wpf system-tray
source share
3 answers

Nothing comes to WPF. Of the implementations you can find on the net, there is a β€œsimple” one that uses WinForms:

http://msdn.microsoft.com/en-us/library/aa972170.aspx

But I also like it (can be used for hints with balls)

http://www.codeproject.com/KB/WPF/wpf_notifyicon.aspx

+5
source share

Winform:

One approach is to set the Cancel property to FormClosingEventArgs in the FormClosing event of your window and collapse to the tray instead. To minimize the tray, see this article:

Window tray minimizer

The Code Project contains more articles on this topic, but the one I worked with worked for me.

WPF:

I never had to do this in WPF, but still tried to find a solution. I found this:

Creating a Tray Icon for a WPF Application

You will find that the code works, but I recommend testing. The article discusses the opening of an application that is minimized in the tray.

You can also find this sample on MSDN useful:

Notification Icon Example

+8
source share

In winforms, you can reload WndProc and see the WM_CLOSE message.

WM_CLOSE = 0x0010 protected override void WndProc(ref Message m) { if(m.Msg == WM_CLOSE) { this.Hide(); trayIcon.Show(); } } 
+1
source share

All Articles