I created a new form with buttons labeled as “OK” and “Cancel”
This form pops up by clicking a button from the first form. I’d like to run some code only if the “OK” button was clicked in the new custom form. This is not a MessageBox().
So far I have something like this:
CustomForm c = new CustomForm();
DialogResult r = c.DialogResult;
c.ShowDialog();
if (r == DialogResult.OK)
{
//Run code
}
This however isn’t working. How do I code this properly? I also set the “OK” button as the AcceptButton in CustomForm.
Perhaps prefer compacting it like so:
Also, remember you have to set the DialogResult of the button on the other form to be OK:
DialogResultis anenum. As such, it is copied by value.. not by reference.