How to Exit from this Application in Window Form

Step 1: Form



GO to form "Events" there is a event "FormClosing" click on it.

Step 2: Code
 
 
 

Private void Form2_FormClosing(Object sender , FormClosing EventArgs e)

{

    Application.Exit();

}

If you want to close your application at button click event write this code

private void btnclose_Click(object sender, EventArgs e)

{

    This.close();

 

If you want to that before closing a Pop Up show that you want to close this application or not then.

Private void Form2_FormClosing(Object sender , FormClosing EventArgs e)

{

     DialogResult dialog = MessageBox.show("Do you want to close application", "Exit", MessageBoxButtons.YesNo);

     if(dialog ==DialogResult.Yes)

     {

         Application.Exit();

     }

    elseIf(dialog ==DialogResult.No)

    {

        e.cancel= true;

    }

}

Step 3: Output

Now run your application and close this application as gracefully.

you can go on my blog_munesh

Ebook Download
View all
Learn
View all