// Save the current file******************************************************************* private void fileMenuSave_Click(object sender, EventArgs e) { // First, check to see if child forms are open. If so, ask if want to save. PracticeForm child = this.ActiveMdiChild as PracticeForm; if (child != null) // don't try to save what doesn't exist { DialogResult notSoFast = MessageBox.Show("Do you want to save changes?", "SAVE CHANGES", MessageBoxButtons.YesNo); if (notSoFast == DialogResult.Yes) // save { child.writeFile(); } else // don't want to save... { Application.Exit(); } } }
// for closing practice forms************************************************************** private void fileMenuClose_Click(object sender, EventArgs e) { // identify the active child form PracticeForm child = this.ActiveMdiChild as PracticeForm; DialogResult notSoFast = MessageBox.Show("Do you want to save changes?", "SAVE CHANGES", MessageBoxButtons.YesNo); if (notSoFast == DialogResult.Yes) // save and exit { try // can't close and save a null file { // call the active child form to serialize the newly edited file child.writeFile(); // reset the window open boolean variable if (child.Text == "Lake Dental Clinic") { dentalOpen = false; } if (child.Text == "Pickens Foot Clinic") { footOpen = false; } // close the child form child.Close(); } catch (NullReferenceException) { MessageBox.Show("There's no file open."); } } else // don't want to save... { this.Close(); } }