Example #1
0
        /**
         *  CreateTopLevelWindow implements creating a new form. This is the real 'constructor'.
         *  First, we check if the fileName matches any of the Open Forms in the MultiSDIApplication. If it
         *  does, we just activate that form. If it doesn't we create a new one using OpenFile, a method found
         *  in this class (TopLevelForm) to open a file, then we activate the new window.
         */
        public static TopLevelForm CreateTopLevelWindow(string fileName)
        {
            // If fileName is not empty
            if (!string.IsNullOrEmpty(fileName))
            {
                // Loop through the open forms in MultiSDIApplication
                foreach (TopLevelForm openForm in Application.OpenForms)
                {
                    // If the file we're trying to open is already open, i.e. file names match
                    if (string.Compare(openForm.fileName, fileName, true) == 0)
                    {
                        // Bring form to top
                        openForm.Activate();
                        return(openForm);
                    }
                }
            }
            // Otherwise, create a new one with the given fileName
            TopLevelForm form = new TopLevelForm();

            form.OpenFile(fileName);
            form.Show();

            // Bring form to top
            form.Activate();
            return(form);
        }
        /**
         *  CreateTopLevelWindow helper method. Parses the command line args and grabs the file name, then passes the file
         *  name to TopLevelForm's CreateTopLevelWindow method to create a Top Level Window with the given file name.
         */
        TopLevelForm CreateTopLevelWindow(ReadOnlyCollection <string> args)
        {
            // Get file name, if provided
            string fileName = (args.Count > 0 ? args[0] : null);

            // Create new top level form
            return(TopLevelForm.CreateTopLevelWindow(fileName));
        }