A dialog box appears with the Yes and No buttons.

var close = MessageBox.Show("Вы точно хотите закрыть файл?", "Закрытие", MessageBoxButtons.YesNo); if (close == DialogResult.Yes) { Exit(); } if (close == DialogResult.No) { //Чтобы тут такого написать, чтобы программа продолжила работу ? } 

Because by default, regardless of what you click, a condition will occur that the Yes button is pressed.

  • one
    write nothing, kill this check at all - Dmitry
  • 2
    Where does this code run? Likely in the form closing handler? Edit the question by adding information. - Alexander Petrov
  • Well, it worked here. There is another problem. When I try to close the form. I do exactly the same condition, but if I click no, it just completes the program, how to make an event wait for any further action from the user? - user209821
  • @ user209821 additional questions should be asked exactly as questions, not in the comments - Schullz

1 answer 1

 e.Cansel = MessageBox.Show ( "Вы точно хотите закрыть файл?", "Закрытие", MessageBoxButtons.YesNo ) == DialogResult.No; 
  • Can you get rid of horizontal overflow? Well, zazyazya! - VladD
  • @VladD, 116 characters halfway across a standard screen. If SO changes the design, it won't scroll))) - Qwertiy
  • @VladD, got rid of. Although in the code I would not want to see such a design. - Qwertiy
  • Yeah, I, too, such formatting is somehow not very. I would format it like this: pastebin.com/2zZwZwA3 (at the same time I separated the messagebox logic from the cancellation logic). - VladD
  • Although yes, in my code the border is 120 characters :) When copying to SO, you have to reformat. - VladD