Send to tray on Close

江枫思渺然 提交于 2019-12-21 12:08:27

问题


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


回答1:


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




回答2:


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




回答3:


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();
      }

    }


来源:https://stackoverflow.com/questions/937792/send-to-tray-on-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!