I have an example WinForm application called "Restoring.exe". When minimizing the window, it will move to the system tray and will be hidden on the taskbar. If I click on the notification icon in the system tray, a window will appear in front.
public void notifyicon_MouseClick(object sender, System.EventArgs e)
{
notifyicon.Visible = false;
Show();
Activate();
TopMost = true;
BringToFront();
this.WindowState = FormWindowState.Normal;
}
But my actual requirement is that when you first click on the application, you must restore the application from the taskbar.
For this, I tried the code below
Program.cs:
static void Main()
{
if (IsServiceManagerAlreadyRunning())
{
Form1 form1 = new Form1();
form1.Restore();
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
Form1.cs:
public void Restore()
{
notifyicon.Visible = false;
Show();
Activate();
TopMost = true;
BringToFront();
this.WindowState = FormWindowState.Normal;
}
My actual problem is , if the application is already running, the Restore method starts, and all the actions listed in it are performed, and the window appears in front. But after completing these steps, the window returns to the system tray. Do not sit in front.
- ?