#region Using directives using System; using System.Collections.ObjectModel; using System.Windows.Forms; using Microsoft.VisualBasic.ApplicationServices; #endregion namespace SingleMDISample { public class SingleMDIApplication : WindowsFormsApplicationBase { private static SingleMDIApplication application; internal static SingleMDIApplication Application { get { if( application == null ) { application = new SingleMDIApplication(); } return application; } } // 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.CreateMDIChildWindow(this.CommandLineArgs); } // Load subsequent MDI child form protected override void OnStartupNextInstance(StartupNextInstanceEventArgs e) { this.CreateMDIChildWindow(e.CommandLine); } private void CreateMDIChildWindow(ReadOnlyCollection args) { // Get file name, if provided string fileName = (args.Count > 0 ? args[0] : null); // Ask MDI parent to create a new MDI child and open // file, if one was passed ((MDIParentForm)this.MainForm).CreateMDIChildWindow(fileName); } } }