/// <summary> /// Opens a new Text Editor window instance as a child window and opens an existing text file with it. /// </summary> private void FileOpen(object sender, EventArgs e) { // If there's at least one MdiChild. if (this.MdiChildren.Length > 0) { // If current window is a text editor window. if (this.ActiveMdiChild.GetType() == typeof(formTextEditor)) { // Cast the active window to a texteditor window. formTextEditor texteditorInstance = (formTextEditor)this.ActiveMdiChild; // Call the active window's open operation. texteditorInstance.FileOpen(sender, e); } // The current window is not a textedtor window. Report that. else { MessageBox.Show("Open is not supported for the current active window.", "Open Not Suported"); } } // There is no child window. Report that. else { formTextEditor texteditorInstance = new formTextEditor(); texteditorInstance.MdiParent = this; texteditorInstance.Show(); // Cast the active window to a whiteboard window. formTextEditor texteditorInstance2 = (formTextEditor)this.ActiveMdiChild; // Call the active window's copy operation. texteditorInstance2.FileOpen(sender, e); } }
/// <summary> /// Detect the window type,; if it supports paste, call that window's paste operation. /// </summary> private void EditPaste(object sender, EventArgs e) { // If there's at least one MdiChild. if (this.MdiChildren.Length > 0) { // If current window is a whiteboard window. if (this.ActiveMdiChild.GetType() == typeof(formWhiteboard)) { // Cast the active window to a whiteboard window. formWhiteboard whiteboardInstance = (formWhiteboard)this.ActiveMdiChild; // Call the active window's paste operation. whiteboardInstance.EditPaste(sender, e); } // If current window is a whiteboard window. else if (this.ActiveMdiChild.GetType() == typeof(formTextEditor)) { // Cast the active window to a whiteboard window. formTextEditor texteditorInstance = (formTextEditor)this.ActiveMdiChild; // Call the active window's paste operation. texteditorInstance.EditPaste(sender, e); } // The current window is not a whiteboard window. Report that. else { MessageBox.Show("Paste is not supported for the current active window.", "Paste Not Suported"); } } // There is no child window. Report that. else { MessageBox.Show("You must select a window that allows paste to do that.", "Paste Not Supported"); } }
/// <summary> /// Opens a new Text Editor window instance as a child window. /// </summary> private void FileNew(object sender, EventArgs e) { formTextEditor texteditorInstance = new formTextEditor(); texteditorInstance.MdiParent = this; texteditorInstance.Show(); }
/// <summary> /// Open a save dialog and save the file to the location chosen by the user. /// </summary> private void FileSaveAs(object sender, EventArgs e) { // Check if windows are actually open. if (this.MdiChildren.Length > 0) { // If the selected window is a whiteboard window. if (this.ActiveMdiChild.GetType() == typeof(formWhiteboard)) { // Call the whiteboard window's Save As function. formWhiteboard whiteboardInstance = (formWhiteboard)this.ActiveMdiChild; whiteboardInstance.FileSaveAs(sender, e); } // If the selected window is a text edtior window. else if (this.ActiveMdiChild.GetType() == typeof(formTextEditor)) { // Cast the active window to a texteditor window. formTextEditor texteditorInstance = (formTextEditor)this.ActiveMdiChild; // Call the active window's save operation. texteditorInstance.FileSaveAs(sender, e); } // Otherwise, this is some other window that doesn't allow saving. Report error. else { MessageBox.Show("This window type does not support saving.", "Save As Not Supported"); } } // No child windows are open. Report an error. else { MessageBox.Show("You need to have an open window to save.", "Save As Not Supported"); } }
/// <summary> /// Saves the file if the path is known, or calls "Save As" if it is not known. /// </summary> private void FileSave(object sender, EventArgs e) { // If there's at least one MdiChild. if (this.MdiChildren.Length > 0) { // If current window is a text editor window. if (this.ActiveMdiChild.GetType() == typeof(formTextEditor)) { // Cast the active window to a texteditor window. formTextEditor texteditorInstance = (formTextEditor)this.ActiveMdiChild; // Call the active window's save operation. texteditorInstance.FileSave(sender, e); } // The current window is not a textedtor window. Report that. else { MessageBox.Show("Save is not supported for the current active window.", "Save Not Suported"); } } else { MessageBox.Show("You must select a window that allows save to file.", "Save Not Supported"); } }