Пример #1
0
 protected override void OnClosing(CancelEventArgs e)
 {   // maybe we need to save the project
     ToolBars.SaveToolbarPositions(topToolStripContainer);
     Settings.SaveGlobalSettings();
     // ToolStripManager.SaveSettings(this); // save the positions of the toolbars (doesn't work correctly)
     base.OnClosing(e);
 }
Пример #2
0
 public CadForm(string[] args)
 {
     InitializeComponent(); // makes the cadCanvas and the propertiesExplorer
     KeyPreview = true;     // used to filter the escape key (and maybe some more?)
     cadFrame   = new CadFrame(propertiesExplorer, cadCanvas, this);
     cadFrame.ProgressAction  = (show, percent, title) => { this.ProgressForm.ShowProgressBar(show, percent, title); };
     cadCanvas.Frame          = cadFrame;
     propertiesExplorer.Frame = cadFrame;
     // show this menu in the MainForm
     MenuWithHandler[] mainMenu = MenuResource.LoadMenuDefinition("SDI Menu", true, cadFrame);
     #region DebuggerPlayground, you can remove this region
     // in the following lines a "DebuggerPlayground" object is created via reflection. This class is a playground to write testcode
     // which is not included in the sources. This is why it is constructed via reflection, there is no need to have this class in the project.
     Type dbgplygnd = Type.GetType("CADability.Forms.DebuggerPlayground", false);
     if (dbgplygnd != null)
     {
         MethodInfo connect = dbgplygnd.GetMethod("Connect");
         if (connect != null)
         {
             mainMenu = connect.Invoke(null, new object[] { cadFrame, mainMenu }) as MenuWithHandler[];
         }
     }
     #endregion DebuggerPlayground
     Menu = MenuManager.MakeMainMenu(mainMenu);
     cadFrame.FormMenu = Menu;
     // open an existing Project or create a new one
     ToolBars.CreateOrRestoreToolbars(topToolStripContainer, cadFrame);
     Application.Idle += new EventHandler(OnIdle); // update the toolbars (menus are updated when they popup)
 }
Пример #3
0
 private void ParentForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     // maybe we need to save the project
     ToolBars.SaveToolbarPositions(toolStripContainer);
     Settings.SaveGlobalSettings();
     // ToolStripManager.SaveSettings(this); // save the positions of the toolbars (doesn't work correctly)
     cadFrame.Dispose();
     Application.Idle -= OnIdle;
 }
Пример #4
0
        protected override void OnHandleCreated(EventArgs e)
        {
            setupParentForm();

            // open an existing Project or create a new one
            ToolBars.CreateOrRestoreToolbars(toolStripContainer, cadFrame);
            Application.Idle += new EventHandler(OnIdle); // update the toolbars (menus are updated when they popup)

            base.OnHandleCreated(e);
        }
Пример #5
0
        /// <summary>
        /// Create some standard toolbars and restore the positions from the application settings
        /// </summary>
        /// <param name="topToolStripContainer"></param>
        /// <param name="commandHandler"></param>
        public static void CreateOrRestoreToolbars(ToolStripContainer topToolStripContainer, ICommandHandler commandHandler)
        {
            string savedToolbarPosition = Properties.Settings.Default["ToolbarPositions"] as string;
            SortedDictionary <string, Point> toolBarPosition = new SortedDictionary <string, Point>();

            foreach (string position in savedToolbarPosition.Split(';'))
            {
                string[] parts = position.Split(':');
                if (parts.Length == 2)
                {
                    string[] xy = parts[1].Split(',');
                    if (xy.Length == 2)
                    {
                        try
                        {
                            toolBarPosition[parts[0]] = new Point(int.Parse(xy[0]), int.Parse(xy[1]));
                        }
                        catch { }
                    }
                }
            }
            if (toolBarPosition.Count == 5)
            {   // it is a valid dictionary
                // we have to sort the entries by location from top left to bottom right
                string[] keys = new string[toolBarPosition.Count];
                toolBarPosition.Keys.CopyTo(keys, 0);
                Array.Sort(keys, delegate(string s1, string s2)
                {
                    int c = toolBarPosition[s1].Y.CompareTo(toolBarPosition[s2].Y);
                    if (c == 0)
                    {
                        c = toolBarPosition[s1].X.CompareTo(toolBarPosition[s2].X);
                    }
                    return(c);
                });
                for (int i = 0; i < keys.Length; i++)
                {
                    if (toolBarPosition.TryGetValue(keys[i], out Point point))
                    {
                        topToolStripContainer.TopToolStripPanel.Join(ToolBars.MakeStandardToolStrip(keys[i], commandHandler), point);
                    }
                }
            }
            else
            {
                topToolStripContainer.TopToolStripPanel.Join(ToolBars.MakeStandardToolStrip("Object", commandHandler), 0);
                topToolStripContainer.TopToolStripPanel.Join(ToolBars.MakeStandardToolStrip("Zoom", commandHandler), 0);
                topToolStripContainer.TopToolStripPanel.Join(ToolBars.MakeStandardToolStrip("File", commandHandler), 0);
                topToolStripContainer.TopToolStripPanel.Join(ToolBars.MakeStandardToolStrip("Snap", commandHandler), 1);
                topToolStripContainer.TopToolStripPanel.Join(ToolBars.MakeStandardToolStrip("Construct", commandHandler), 1);
            }
        }
Пример #6
0
 private void OnIdle(object sender, EventArgs e)
 {
     ToolBars.UpdateCommandState(topToolStripContainer.TopToolStripPanel);
 }