Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirmation before closing

net windows form application. I have a combo box and a text box and a close window button. Now If I make any change in the combo box or textbox and click on the close window button, it should prompt the user to save the modifications.. If no modification are made ( The user will just run the application, doesnt make any modification) then it should not prompt the user. It should close directly.. How can I do this?

like image 614
saeed Avatar asked Jan 21 '23 22:01

saeed


2 Answers

An easy way to do it is by adding a dirty member to the form, which I set to true whenever anything changes and then check it whenever the form is closing .

like image 114
Hans Olsson Avatar answered Jan 24 '23 11:01

Hans Olsson


Override the OnClosing method of your form (or attach to the Closing event). In the handler check for modifications and display a message box to the user. If you do not want the form to close just set the e.Cancel property to false before returning.

like image 38
munissor Avatar answered Jan 24 '23 11:01

munissor