To send the application to the system tray, you can add a NotifyIcon
to the designer of your form
and make it visible whenever you minify or (in this case) close the application.
To add a context menu to your NotifyIcon
you can add a ContextMenuStrip
(still in the form designer) and bind the menu to NotifyIcon
using the ContextMenuStrip
property.
To show NotifyIcon
whenever the application is closed , you can implement the FormClosing
event in your main form , 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 get the visibility of your NotifyIcon
before closing the application, otherwise the icon will remain in the system tray until the user passes the mouse above the icon. (I do not know why this behavior, but I have suffered a lot with it).