开发者

MessageBox close another form

Hello Guys I have msg box when i press on yes its close that form which calls msg开发者_运维问答 box how can i do when msg box dialogresult = ok close only himself


Set the DialogResault property to None for the button which its event handler open the MessageBox.

Good luck!


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

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


Maybe you're assigning the result to the DialogResult property of the parent form, (see http://msdn.microsoft.com/en-us/library/system.windows.forms.form.dialogresult.aspx) and in particular from the remark section :

" If the form is displayed as a dialog box, setting this property with a value from the DialogResult enumeration sets the value of the dialog box result for the form, hides the modal dialog box, and returns control to the calling form."

Use:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜