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();            
        }

Would something like this work (if you used Visible = false in your resize method instead of Hide())?

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
        if(this.WindowState == FormWindowState.Minimized)
               this.WindowState = FormWindowState.Normal;
       this.Visible = true;          
}

Edited 6 Years Ago by jonsca: n/a

Comments
Thanks.
This question has already been answered. Start a new discussion instead.