Thursday, May 13, 2010

How to prevent form closing in C# windows application

In some cases you need to prevent closing the application/form when user clicks windows close button.

Use the following code snippet to do so

 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
            }
        }

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

No comments: