Reputation: 33
Using winforms, when error occures, DialogResult will be Ok and the form will close, Is there a way for the form not to close ? I need DialogResult = DialogResult.OK;
that part to be in my code too.
private void btnSave_Click(object sender, EventArgs e)
{
if(NotERROR)
{
doSomething;
}
else
{
MessageBox.Show("ERROR");
}
DialogResult = DialogResult.OK;
}
Upvotes: 0
Views: 57
Reputation: 35646
set DialogResult.OK
only when there is no error, inside if block:
private void btnSave_Click(object sender, EventArgs e)
{
if (NotERROR)
{
DoSomething();
DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show("ERROR");
}
}
Upvotes: 3