Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am trying to minimize the form to system tray. I have written a piece of code. But the only problem i am facing is that when i try to restore the window from system tray. Win Form appears in taskbar but has lost focused means it doesnt appear on the screen automatically i have to click on taskbar to restore it....
Here is my code
private void Form1_Resize(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Minimized)
    {
        notifyIcon1.Visible = true;
        this.Hide();
    }
    else if (this.WindowState == FormWindowState.Normal)
    {
        notifyIcon1.Visible = false;
    }
}

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
    this.Show();
}
Posted

1 solution

Catch the event that displays the form when you're restoring it from the systray, and add this line to the event handler.

this.WindowState = FormWindowState.Normal;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900