Form.ShowDialog(), how to disable exiting on button click

  • Thread starter Thread starter alberto
  • Start date Start date
A

alberto

(using Windows CE, C#)
I have a form that is called with frmname.ShowDialog(), and it of
course has an OK button which returns a DialogResult.OK.
How can I disable closing the form when I want to (specifically, when
I get an exception from a database operation). In that case, instead
of exiting the form I want to display a MessageBox, and continue form.

Thanks in advance

Alberto
 
Hi alberto,

I guess you'd like something liker that ?

private void MyModalForm_Closing(object sender, CancelEventArgs e)
{
try
{
throw new Exception("oh rage, oh désespoir, oh
vieillesse ennemie ...");
}
catch (Exception ex)
{
MessageBox.Show("An error occured : " + ex.Message);
e.Cancel = true;
}
}
}

alberto wrote :
 
Back
Top