To send the application to the system tray, you can add a NotifyIcon
in the designer of your form
and make it visible whenever you want to minimize or (in this case) close the application.
To add a context menu to your NotifyIcon
you can add a ContextMenuStrip
(still in the designer of form) and link the menu to NotifyIcon
using the property ContextMenuStrip
.
To show the NotifyIcon
where the application is closed, you can implement the event FormClosing
in his form would be something like:
public form1_FormClosing(object sender, EventArgs e)
{
e.Cancel = true; // Cancelar o fechamento do form
Hide(); // Ocultar o form
// use this.WindowState = FormWindowState.Minimized; para minimizar
notifyIcon.Visible = true; // Mostrar o notify icon
}
An important point is that you can not forget to take the visibility of your NotifyIcon
before closing the application, otherwise the icon will remain in the system tray until the user passes the mouse over the icon. (I don’t know why this behavior, but I’ve suffered a lot with it).