Set the form's DialogResult
:
this.DialogResult = DialogResult.OK;
this.Close();
This would cause any opener that opened this form with ShowDialog()
to get the given DialogResult
as the result.
I assume you're using Windows Forms...
A couple of ways.
For OK - set AcceptButton on the form to the OK button. For Cancel - set Cancelbutton on the form to the cancel button.
OR, you can manually set the forms DialogResult to DialogResult.OK or DialogResult.Cancel and then close the form programatically.
Directly, in the properties of the button itself, there is the DialogResult property that can be set to OK/Cancel/Yes/No/etc... As the others have said, this can also be set programmatically.
In the properties of the form the button is on, set the AcceptButton property to your button. This will also do things like trigger the button when you hit the enter key, and highlight the button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With