I have an winforms application, in which Im making it to hide in the tray menu when clicking the close button. I have used trayicon and notifyicon in this. The following is the code
For minimizing to the system tray
public void MinimizeToTray()
{
try
{
this.WindowState = FormWindowState.Minimized;
TrayIcon.Visible = true;
TrayIcon.ShowBalloonTip(1000);
ShowInTaskbar = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//Load the tray menu
private void LoadTrayMenu()
{
TrayMenu.Items.Add("Exit");
TrayMenu.Items[0].Click += new System.EventHandler(this.Dispose_Click);
TrayIcon.ContextMenuStrip = TrayMenu;
}
//Close the application
private void Dispose_Click(object Sender, EventArgs e)
{
TrayIcon.Visible = false;
TrayIcon.Icon = null;
Application.Exit();
}
The above part works fine for me, ie I can minimize the application to the traymenu, then re-size to the original form, the close it. But when the application is minimized to the system tray, if at that time i press All-Tab i can view the application. Using which the application can be brought back to the original form instead of clicking from the system tray.
I have viewed these examples
How do I minimize a WinForms application to the notification area?
Best way to hide a window from the Alt-Tab program switcher?
But none of them shows how to hide the application from the Alt-Tab switcher when the application is in the system tray.
Im fine if the application is viewable in the Alt-Tab switcher when the application is not in the system tray.
Any help would be appreciated