singlemdiapplication.cs

来自「中文名:Windows Forms 程序设计 英文名:Windows Form」· CS 代码 · 共 45 行

CS
45
字号
#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 + =
减小字号Ctrl + -
显示快捷键?