Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling Cancel Button in Yes/No/Cancel Messagebox in FormClosing Method

I put a Yes/No/Cancel Messagebox in FormClosing Method of my form. and now this is Message box text: Do You Want to Save Data?

I am not a profesional and not know how to handle if user clicked Cancel Button? Exactly the result of clicking on Cancel Button must be The form remain open.
How to prevent Closing my form in FormClosing method?

I wrote So far: ;)

DialogResult dr = MessageBoxFarsi.Show("Do You Want to Save Data?","",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Warning);

//...
else if (dr == DialogResult.Cancel)
{
    ???
}

Please Help me to complete my code!
Thanks

like image 969
Mehdi Avatar asked Nov 27 '22 12:11

Mehdi


1 Answers

FormClosing has a Boolean parameter which, if set to True when the function returns, will cancel closing the form, IIRC.

EDIT: For example,

private void Form1_FormClosing(Object sender, FormClosingEventArgs e) {
    // Set e.Cancel to Boolean true to cancel closing the form
}

See here.

like image 129
Matthew Iselin Avatar answered Dec 16 '22 01:12

Matthew Iselin