Monday, May 17, 2010

How to minimize window from closing C# windows application

To minimize the window when user closes the form, use the code below.

 private void Alerts_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {               
                e.Cancel = true;
        this.WindowState = FormWindowState.Minimized;

            }           
        }

Add To Google BookmarksStumble ThisFav This With TechnoratiAdd To Del.icio.usDigg ThisAdd To RedditTwit ThisAdd To FacebookAdd To Yahoo