Ejemplo n.º 1
0
        /// <summary>
        /// This method handles the case where the user decides to close the
        /// currently active spreadsheet by clicking the X icon on top-right.
        /// When prompted to save the sheet (if it is unsaved), if the user clicks
        /// cancel, exists. If the user clicks Yes, saves the file. And if the user
        /// clicks Cancel, the program remains open.
        /// </summary>
        /// <param name="e">Provides the Form closing event arguments</param>
        private void HandleXClose(FormClosingEventArgs e)
        {
            if (spreadsheet.Changed && !closedFromMenu)
            {
                DialogResult result = window.Message("There are some unsaved changes."
                                                     + " Would you like to save your changes before closing?",
                                                     "Save Before Exiting?", MessageBoxButtons.YesNoCancel,
                                                     MessageBoxIcon.Warning);

                // if seleced 'Yes', then save the file. If the change is still true
                // (i.e, user selected cancel in the Save dialog), don't close the sheet.
                if (result == DialogResult.Yes)
                {
                    window.PerformSaveClick();
                    if (spreadsheet.Changed)
                    {
                        e.Cancel = true;
                    }
                }
                // else if selected cancel, don't close the window. Else, let the sheet
                // window close.
                else if (result == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
            }
        }