示例#1
0
        /// <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);
            }
        }
示例#2
0
 /// <summary>
 /// Loads the last saved settings into the preview.
 /// </summary>
 /// <param name="previewForm">The preview form.</param>
 public static void Load(C1dViewForm previewForm)
 {
     try
     {
         var settings = Properties.Settings.Default;
         if (settings == null)
         {
             return;
         }
         if (settings.C1dViewSettings == null)
         {
             Save(previewForm);
             return;
         }
         var vs = settings.C1dViewSettings;
         // main window position:
         if (vs.MainWindowBounds.Width >= MinMainWindowSize.Width &&
             vs.MainWindowBounds.Height >= MinMainWindowSize.Height &&
             vs.MainWindowBounds.X >= 0 && vs.MainWindowBounds.Y >= 0)
         {
             previewForm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
             previewForm.Bounds        = vs.MainWindowBounds;
         }
         // recent documents:
         C1dViewForm.RecentDocuments.Clear();
         if (vs.RecentDocuments != null)
         {
             C1dViewForm.RecentDocuments.AddRange(vs.RecentDocuments);
         }
     }
     catch
     {
         // ignore settings errors, not much to do here.
     }
 }
示例#3
0
 /// <summary>
 /// Saves current settings.
 /// </summary>
 /// <param name="previewForm">The preview form.</param>
 public static void Save(C1dViewForm previewForm)
 {
     try
     {
         var settings = Properties.Settings.Default;
         if (settings == null)
         {
             return;
         }
         if (settings.C1dViewSettings == null)
         {
             settings.C1dViewSettings = new C1dViewSettings();
         }
         var vs = settings.C1dViewSettings;
         // main window position:
         vs.MainWindowBounds = previewForm.Bounds;
         // recent documents:
         vs.RecentDocuments = new List <Pair <string, string> >();
         vs.RecentDocuments.AddRange(C1dViewForm.RecentDocuments);
         //
         settings.Save();
     }
     catch
     {
         // ignore settings errors, not much to do here.
     }
 }
示例#4
0
        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();
        }