I would like to get a response from the user when X is selected to close the child form but instead the formclosing event just closes the form
Can anyone help? This is my code below:
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult responseDialogResult;
if (isDirtyBoolean)
{
responseDialogResult = MessageBox.Show(
"The data on the form has changed. Do you want to save the contents of the form to a file?", "File Change",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (responseDialogResult == DialogResult.Yes)
{
saveToolStripMenuItem_Click(sender, new System.EventArgs());
}
VulpesPosted May 28, 2014, 6:49 PM
Incidentally, you can tell whether the form is closing on account of user action (such as clicking the 'X' button) by testing if e.CloseReason == CloseReason.UserClosing.
Although it may not be relevant here, you can also cancel the closing of the form by setting e.Cancel to true.