ClickOnce creates defect runtime code C sharp Top Online Courses From ProgrammingKnowledge Python Programming Course …



  1. private void Form_Main_FormClosing(object sender, FormClosingEventArgs e)
    DialogResult result = MessageBox.Show("EXIT?", "Exit Program", MessageBoxButtons.YesNo);

    if (result != DialogResult.Yes)
    e.Cancel = true;

  2. If you want to fix your code so the message only shows once replace "Application.Exit();" with "this.Dispose();". It fixed the issue in my program.

  3. guys i am having problem when saving my c# application it is giving error of some kind i have to make project and have to save it to later connect to mysql i don"t know what to do??

  4. just get rid of the first IF for the YES option 🙂 …if you then save it and click on yes it closes the application anyways, and the NO option works as intended… hope it helps its the easiest way…

  5. Try setting the exit button to Application.Exit();

    Leave the dialog block of code in the FormClosing Event. 

    Then it will only ask the dialog result once during the FormClosing Event

  6. sorry guys… I already solve the e.Cancel error and is now OK… I did mistake of putting the code in the different procedures… my bad… thanks ProgrammingKnowledge for this code….

  7. anyone can help me.. this application.exit(); work fine but e.Cancel is not…error – it says "does not contain definition"

  8. There are two ways to exit:
    1. Application.ExitThread();
    2. Release Resource  and then exit:

  9. There in your tutorial Form1 – .Hide and it is in RAM. WHen you close 2nd form – programm asks 2 times for closing – 1st time for Form2 and second time for Form1. How can i "kill" form1 and get only 1 message "Are you sure want to exit" instead of 2?

  10. Just remove the else and keep the if and the code will work just fine..

         DialogResult form1 = MessageBox.Show("Do you really want to close the program?",
                    "Exit", MessageBoxButtons.YesNo);

                if (form1 == DialogResult.Yes)

    This worked for me!

  11. The code works fine with only an adjustment:

    DialogResult dialog = MessageBox.Show("Do you realy whant to close the application?", "Exit");

  12. How would you make this a class so that if your application had multiple forms you could reuse the same code rather than wasting a lot of time repeating the code in each form?  Thanks

Leave A Reply

Please enter your comment!
Please enter your name here