Пример #1
0
 /// <summary>
 /// Saves the currently selected text editor, or calls the "Save As" event
 /// handler if the file has not already been saved.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void FileSave(object sender, EventArgs e)
 {
     // If there is an active window:
     if (this.MdiChildren.Length > 0)
     {
         // If the text editor window is the currently active window...
         if (this.ActiveMdiChild.GetType() == typeof(formTextEditor))
         {
             // ...call the text editor's FileSave event handler.
             formTextEditor textEditorInstance =
                 (formTextEditor)this.ActiveMdiChild;
             textEditorInstance.FileSave(sender, e);
         }
         // If the text editor is not the active window...
         else
         {
             // ...display an appropriate message.
             MessageBox.Show("The Save operation is not supported by the " +
                             "currently selected window.", "Operation Not Supported");
         }
     }
     // If there are no active windows...
     else
     {
         // ...display an appropriate message.
         MessageBox.Show("You must have an open text editor window to Save.",
                         "Operation Not Supported");
     }
 }
Пример #2
0
        /// <summary>
        /// Creates a new text editor child window.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FileNew(object sender, EventArgs e)
        {
            formTextEditor textEditorInstance = new formTextEditor();

            textEditorInstance.MdiParent = this;
            textEditorInstance.Show();
        }
Пример #3
0
        /// <summary>
        /// Closes the currently selected text editor window.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FileClose(object sender, EventArgs e)
        {
            // If there is an active window:
            if (this.MdiChildren.Length > 0)
            {
                // If the text editor window is the currently active window...
                if (this.ActiveMdiChild.GetType() == typeof(formTextEditor))
                {
                    // ...call the text editor's close event handler.
                    formTextEditor textEditorInstance =
                        (formTextEditor)this.ActiveMdiChild;
                    textEditorInstance.FileClose(sender, e);
                }

                // If the Car Inventory window is the currently active window...
                else if (this.ActiveMdiChild.GetType() == typeof(formCarInventory))
                {
                    // ...call the window's close event handler.
                    formCarInventory carInventoryInstance =
                        (formCarInventory)this.ActiveMdiChild;
                    carInventoryInstance.ButtonCloseClick(sender, e);
                }

                // If the Average Units Shipped window is the currently active window...
                else if (this.ActiveMdiChild.GetType() == typeof(formAverageUnitsShipped))
                {
                    // ...call the window's close event handler.
                    formAverageUnitsShipped unitsShippedInstance =
                        (formAverageUnitsShipped)this.ActiveMdiChild;
                    unitsShippedInstance.ButtonCloseClick(sender, e);
                }

                // If the Weekly Temperature window is the currently active window...
                else if (this.ActiveMdiChild.GetType() == typeof(formWeeklyTemperature))
                {
                    // ...call the Car Inventory's close event handler.
                    formWeeklyTemperature temperatureInstance =
                        (formWeeklyTemperature)this.ActiveMdiChild;
                    temperatureInstance.ButtonCloseClick(sender, e);
                }

                // If any window specified above is not the active window...
                else
                {
                    // ...display an appropriate message.
                    MessageBox.Show("The Close operation is not supported by the " +
                                    "currently selected window.", "Operation Not Supported");
                }
            }
            else
            {
                MessageBox.Show("To Close a window, a window must first be open.",
                                "Operation Not Supported");
            }
        }
Пример #4
0
        /// <summary>
        /// Opens a saved text editor document.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void FileOpen(object sender, EventArgs e)
        {
            // If there is an active window:
            if (this.MdiChildren.Length > 0)
            {
                // If a text editor window is the currently active window...
                if (this.ActiveMdiChild.GetType() == typeof(formTextEditor))
                {
                    // ...call the text editor's Open event handler.
                    formTextEditor textEditorInstance =
                        (formTextEditor)this.ActiveMdiChild;
                    textEditorInstance.FileOpen(sender, e);
                }
                // If a text editor is not the active window:
                else
                {
                    // Create a new text editor window.
                    formTextEditor textEditorInstance = new formTextEditor();
                    textEditorInstance.MdiParent = this;
                    textEditorInstance.Show();

                    // Set focus to the new window and call the Open event handler.
                    textEditorInstance.Focus();
                    textEditorInstance.FileOpen(sender, e);
                }
            }
            // If there are no active windows:
            else
            {
                // Create a new text editor window.
                formTextEditor textEditorInstance = new formTextEditor();
                textEditorInstance.MdiParent = this;
                textEditorInstance.Show();

                // Set focus to the new window and call the Open event handler.
                textEditorInstance.Focus();
                textEditorInstance.FileOpen(sender, e);
            }
        }