//Checks the see if the user has saved. If so the program closes as normally. Otherwise the warning window displays. private void exitToolStripMenuItem_Click(object sender, EventArgs e) { if (has_Saved) { Close(); } else { warning warning_Window = new warning(); warning_Window.Show(); warning_Window.Controls[1].Click += close; } }
/// <summary> /// If the user closes the program without saving, this function creates a new form warning /// them. If the user has saved, the program closes as normal. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void warning(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { if (has_Saved) { e.Cancel = false; } else { e.Cancel = true; warning warning_Window = new warning(); warning_Window.Owner = this; warning_Window.StartPosition = FormStartPosition.CenterParent; warning_Window.Controls[1].Click += close; warning_Window.ShowDialog(); } } }