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

📄 singlemdiapplication.cs

📁 中文名:Windows Forms 程序设计 英文名:Windows Forms Programming in c# 作者: Chris Sells 翻译: 荣耀 蒋贤哲 出版社:人民
💻 CS
字号:
#region Using directives

using System;
using System.Collections.ObjectModel;
using System.Windows.Forms;

using Microsoft.VisualBasic.ApplicationServices;

#endregion

namespace DocApp {
  public class SingleMDIApplication : WindowsFormsApplicationBase {

    internal static SingleMDIApplication Application = new SingleMDIApplication();

    // Must call base constructor to ensure correct initial 
    // WindowsFormsApplicationBase configuration
    public SingleMDIApplication() : base() {
      
      // This ensures the underlying single-SDI framework is employed, 
      // and OnStartupNextInstance is fired
      this.IsSingleInstance = true;
    }

    // Load MDI parent form and first MDI child form
    protected override void OnCreateMainForm() {
      this.MainForm = new MDIParentForm();
      this.OpenDocument(this.CommandLineArgs);
    }

    // Load subsequent MDI child form
    protected override void OnStartupNextInstance(StartupNextInstanceEventArgs e) {
      this.OpenDocument(e.CommandLine);
    }

    private void OpenDocument(ReadOnlyCollection<string> args) {
      // Get file name, if provided
      string fileName = (args.Count > 0 ? args[0] : null);
      if( string.IsNullOrEmpty(fileName) ) return;
      // Ask MDI parent to create a new MDI child and open
      // file, if one was passed
      ((MDIParentForm)this.MainForm).OpenDocument(fileName);
    }
  }
}

⌨️ 快捷键说明

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