MessageBox closes another form

Hi guys I have a msg field, when I click yes, it closes the form that calls msg box how can I do it when msg box dialogresult = ok close only myself

+5
source share
3 answers

Set the property to the DialogResaultvalue Nonefor the button that the event handler opens the MessageBox.

Good luck

+5
source
DialogResult result = MessageBox.Show("Click yes to close, otherwise click no.", "Message Box Test", MessageBoxButtons.YesNo);

if (result == DialogResult.Yes)
{
  Application.Exit();
}
+1
source

, DialogResult (. http://msdn.microsoft.com/en-us/library/system.windows.forms.form.dialogresult.aspx) , , :

" , DialogResult , ."

:

   if (MessageBox.Show(...) == DialogResult.Yes)
   {
   }
   else
   {
   }
0
source

All Articles