Reputation: 492
What would the advantage of using:
DialogResult.Cancel
Over using:
this.Close()
Would it be just so that you would be able to determine that the user has selected Cancel
?
Upvotes: 3
Views: 89
Reputation: 176946
You can use it value for this kind of purpose
var result = form.ShowDialog();
if (result == DialogResult.OK)
{
}
else if (result == DialogResult.Cancel)
{
//perform soem operation
}
So if you want to perform some operation on the result of dialog you can use this.
Note :
Both of this ok and cancel operation on dialog close your dialog, and by catching ok and cancel value you can perform extra task as given in above example.
Upvotes: 4
Reputation: 67918
Those consuming your interface, if showing the form with ShowDialog
, would get a result. They would know the user pressed Cancel
.
As an aside. You can set the Form
properties AcceptButton
and CancelButton
. Then, if the form is shown with ShowDialog
, when they are clicked the base Form
will set the DialogResult
and thus the Form
will close on its own.
Upvotes: 4