⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdiparentform.cs

📁 中文名:Windows Forms 程序设计 英文名:Windows Forms Programming in c# 作者: Chris Sells 翻译: 荣耀 蒋贤哲 出版社:人民
💻 CS
字号:
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);
        }
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -