how to put an .net application in system tray when minimized?

后端 未结 3 750
臣服心动
臣服心动 2021-02-03 12:12

can anyone please suggest a good code example of vb.net/c# code to put the application in system tray when minized.

3条回答
  •  没有蜡笔的小新
    2021-02-03 12:42

    You can leverage a built in control called NotifyIcon. This creates a tray icon when shown. @Phillip has a code example that is somewhat complete.

    There is a gotcha though:

    You must override your applications main form Dispose method to call Dispose on NotifyIcon, otherwise it will stay in your tray after application exits.

    public void Form_Dispose(object sender, EventArgs e)
    {
       if (this.Disposing)
          notifyIcon1.Dispose();
    }
    

    Something like that.

提交回复
热议问题