954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to minimize windows form to system tray properly..??

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();            
        }
j4jawaid
Newbie Poster
6 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

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;          
}
jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You