winforms - Form close event in visual studio c# -


i had problem application closing in c#. when hit close button display twice or more times message box. should do?

private void home_formclosed(object sender, formclosedeventargs e) {     dialogresult dialog = messagebox.show("are sure want exit ? ",                              "exit",                               messageboxbuttons.yesno,                               messageboxicon.question);     if (dialog == dialogresult.yes)     {         system.windows.forms.application.exit();     }     else if (dialog == dialogresult.no)     {         this.show();     } } 

you should use form.formclosing event instead of formclosed event. in arguments, find field e.cancel. setting false, keep form open


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -