using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Windows.Forms; namespace MDIClient { partial class MdiParentForm : Form { public MdiParentForm() { InitializeComponent(); } private void newToolStripMenuItem_Click(object sender, EventArgs e) { // Create and show a new child RatesOfReturnForm child = new RatesOfReturnForm(); HookMDIChildFileDocument(child); child.MdiParent = this; child.Show(); } private void openToolStripMenuItem_Click(object sender, EventArgs e) { this.OpenDocument(null); } // For use by Main in processing a file passed via the command line public void OpenDocument(string fileName) { // Let child do the opening RatesOfReturnForm child = new RatesOfReturnForm(); HookMDIChildFileDocument(child); if( child.OpenDocument(fileName) ) { child.MdiParent = this; child.Show(); } else { child.Close(); } } private void exitToolStripMenuItem_Click(object sender, EventArgs e) { // Children will decide if this is allowed or not this.Close(); } private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("RatesOfReturn by Chris Sells, 2003\r\nEnjoy.", "About RatesOfReturn"); } private void MDIChild_FormClosing(object sender, FormClosingEventArgs e) { UnhookMDIChildFileDocument((RatesOfReturnForm)sender); } private void MDIChildFileDocument_ReadDocument(object sender, FileDocumentControlLibrary.SerializeDocumentEventArgs e) { // Add to MRU menu this.mruMenuManager.Add(e.Filename); } private void MDIChildFileDocument_WriteDocument(object sender, FileDocumentControlLibrary.SerializeDocumentEventArgs e) { // Add to MRU menu this.mruMenuManager.Add(e.Filename); // Let file document take care of saving e.Handled = false; } private void mruMenuManager_MruMenuItemClick(object sender, MruControlLibrary.MruMenuItemClickEventArgs e) { this.OpenDocument(e.Filename); } private void mruMenuManager_MruMenuItemFileMissing(object sender, MruControlLibrary.MruMenuItemFileMissingEventArgs e) { DialogResult res = MessageBox.Show("Remove " + e.Filename + "?", "Remove?", MessageBoxButtons.YesNo); if( res == DialogResult.Yes ) { e.RemoveFromMru = true; } } private void HookMDIChildFileDocument(RatesOfReturnForm mdiChild) { mdiChild.FileDocument.ReadDocument += new FileDocumentControlLibrary.SerializeDocumentEventHandler(MDIChildFileDocument_ReadDocument); mdiChild.FileDocument.WriteDocument += new FileDocumentControlLibrary.SerializeDocumentEventHandler(MDIChildFileDocument_WriteDocument); mdiChild.FormClosing += new FormClosingEventHandler(MDIChild_FormClosing); } private void UnhookMDIChildFileDocument(RatesOfReturnForm mdiChild) { mdiChild.FileDocument.ReadDocument -= new FileDocumentControlLibrary.SerializeDocumentEventHandler(MDIChildFileDocument_ReadDocument); mdiChild.FileDocument.WriteDocument -= new FileDocumentControlLibrary.SerializeDocumentEventHandler(MDIChildFileDocument_WriteDocument); mdiChild.FormClosing -= new FormClosingEventHandler(MDIChild_FormClosing); } private void dragAndDropFileComponent_FileDropped(object sender, DragAndDropFileControlLibrary.FileDroppedEventArgs e) { foreach( string filename in e.Filenames ) { // Only open files with the appropriate extension string extension = Path.GetExtension(filename); if( extension == ".ror" ) { OpenDocument(filename); } else { MessageBox.Show("Can't open files of type " + extension); } } } } }