Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send to tray on Close

How can I send the window minimized to tray when on click close button? Also how to show icon in tray when application start?

like image 736
Sauron Avatar asked Jun 02 '09 03:06

Sauron


3 Answers

WinForm:

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

Window Tray Minimizer

Code Project has more articles on the topic, but the one I linked worked for me.

WPF:

I've never had to do this in WPF but did poke around for a solution. I found this:

Creating a Tray Icon for a WPF Application

You'll find the code works but I recommend testing. The article addresses opening an application minimized to the tray.

You might also find this sample on MSDN useful:

Notification Icon Sample

like image 154
Jay Riggs Avatar answered Nov 01 '22 13:11

Jay Riggs


There is nothing that comes embedded with WPF. From implementations that you can find on the net, there is an "easy" one, that uses WinForms:

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

But I like this one more (can be used for balloon tips too)

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

like image 31
Sergey Aldoukhov Avatar answered Nov 01 '22 12:11

Sergey Aldoukhov


In winforms you can overload WndProc and watch for the WM_CLOSE message.

    WM_CLOSE = 0x0010

    protected override void WndProc(ref Message m)
    {
      if(m.Msg == WM_CLOSE)
      {
        this.Hide();
        trayIcon.Show();
      }

    }
like image 32
scottm Avatar answered Nov 01 '22 13:11

scottm