Exemple #1
0
        // When closing the Text Editor Screen, make sure the loginScreen which was hidden is also closed
        private void TextEditorScreen_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result = UnsavedChanges();

            // Handles the Logout logic
            if (new StackTrace().GetFrames().Any(x => x.GetMethod().Name == "Close"))
            {
                if (result == DialogResult.Yes)
                {
                    saveAsToolStripMenuItem_Click(sender, e);
                    loginScreen.Show();
                }

                // If user wish to not save the file or the current text, then automatically redirect to the Login Screen
                else if (result != DialogResult.Cancel)
                {
                    loginScreen.Show();
                }

                // If user wish to cancel logout, then go back to current text editor
                else if (result == DialogResult.Cancel)
                {
                    // Cancel the log out process
                    e.Cancel = true;
                }
            }

            // Handles when user press "x" logic or ALT+F4
            else
            {
                if (result == DialogResult.Yes)
                {
                    saveAsToolStripMenuItem_Click(sender, e);
                    e.Cancel = false;
                    loginScreen.Close();
                }
                else if (result == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
                else if (result == DialogResult.No)
                {
                    loginScreen.Close();
                    e.Cancel = false;
                }
                else
                {
                    loginScreen.Close();
                }
            }
        }
Exemple #2
0
 private void closeForm_Click(object sender, EventArgs e)
 {
     this.Close();
     loginScreen.Close();
 }