I am using C# here. I have a form where the user can select Yes or No, and if they choose No, a message box appears and asks them if they are sure. If they click No, I want to show the form again. Here’s my code:
public void function()
{
MyForm form = new MyForm();
if (form.ShowDialog() == DialogResult.No)
{
if (MessageBox.Show("Are you sure?",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
runFinished.Dispose();
return;
}
else
{
//Show form again. How??
}
}
}
Thanks everybody for your help!
Arrange that the
NobuttonMyFormdoes the call toMessageBox. Only if the user is sure do you then go on to close the dialog. Your current approach of asking the question after the dialog has closed is incorrect.You can effect the change by making sure that
DialogResultis set in code rather than by the No button’sDialogResultproperty. Then in the click handler for the button you run the message box. If the user confirms the action, then set the formsDialogResulttoDialogResult.No.