/// <summary> /// Creates and shows a new instance of <see cref="C1dViewForm"/>, and loads the specifed file into it. /// If the file is the name of a report definition file, the report selection dialog is shown. /// If the user cancels the dialog, or the file fails to open, the new window is closed. /// </summary> /// <param name="fileName">File to open, or null.</param> /// <returns>The newly created window, or null if no file was loaded.</returns> public C1dViewForm FileNew(string fileName) { var p = this.Location; p.Offset(NEW_WINDOW_OFFSET); var window = new C1dViewForm(); window.StartPosition = System.Windows.Forms.FormStartPosition.Manual; window.Location = p; window.Size = this.Size; window.Show(); if (!string.IsNullOrEmpty(fileName)) { window.cmdFileOpen.UserData = new Pair <string, string>(fileName, null); } window.cmdFileOpen.PerformClick(); if (window.Document == null) { window.cmdFileClose.PerformClick(); return(null); } else { return(window); } }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // method to make first form: Func <C1dViewForm> MakeFirstForm = () => { var viewer = new C1dViewForm(); C1dViewSettings.Load(viewer); viewer.Show(); return(viewer); }; // show all needed forms: if (args != null && args.Length > 0) { C1dViewForm viewer = null; for (int i = 0; i < args.Length; ++i) { if (i == 0) { viewer = MakeFirstForm(); viewer.FileOpen(args[i]); } else { // open next file off last viewer to "cascade" windows: viewer = viewer.FileNew(args[i]) ?? viewer; } } } else { MakeFirstForm(); } // no "main" form - the last one alive will be the main: Application.Run(); }