Example #1
0
        /// <summary>
        /// 删除指定的panel,执行关闭窗口相关的方法,回收该窗体包含的所有资源。
        /// 一般用于Terminate()方法中
        /// </summary>
        public void DeletePanel(string caption)
        {
            if (Program.frmMain.m_Menu.m_MenuTable.ContainsKey("mnu" + caption) && !Program.frmMain.m_Menu.Remove("mnu" + caption)) //如果移除失败,则尝试手动移除一次。
            {
                try
                {
                    System.Windows.Forms.ToolStripItem submenu = (System.Windows.Forms.ToolStripItem)Program.frmMain.m_Menu.m_MenuTable["mnu" + caption];
                    Program.frmMain.menuStrip1.Items.Remove(submenu);
                    if (Program.frmMain.m_Menu.m_MenuTable.ContainsKey("mnu" + caption)) //可能在Remove方法中移除了。
                    {
                        Program.frmMain.m_Menu.m_MenuTable.Remove("mnu" + caption);
                    }
                }
                catch (System.Exception ex)
                {
                    MapWinGIS.Utility.Logger.Dbg("移除可浮动窗体显示菜单失败!菜单名: mnu" + caption + "描述:" + ex.ToString());
                }
            }

            if (m_OnCloseHandlers[caption] != null)
            {
                ArrayList arrylist = m_OnCloseHandlers[caption];
                while (arrylist.Count > 0)
                {
                    //触发绑定该委托的方法。一个窗体可以能绑定了多个OnPanelClose类型的方法,所以一一执行后删除。
                    ((Interfaces.OnPanelClose)(arrylist[0])).Invoke(caption);
                    arrylist.RemoveAt(0);
                }
            }

            if (m_OnCloseHandlers.ContainsKey(caption)) //移除存储该窗体的关闭事件关联的委托
            {
                m_OnCloseHandlers.Remove(caption);
            }

            MWDockPanel floatPanel = m_Panels[caption];

            floatPanel.FormClosing -= new FormClosingEventHandler(MarkClosed);

            if (m_Panels.ContainsKey(caption)) //注销窗体
            {
                if (m_Panels[caption] == null)
                {
                    m_Panels.Remove(caption);
                    return;
                }
                WeifenLuo.WinFormsUI.Docking.DockContent child = m_Panels[caption];
                while (child.Controls.Count > 0)
                {
                    child.Controls.RemoveAt(0);
                }

                m_Panels.Remove(caption);
                child.Close(); //该窗体关闭时会注销掉所有拥有的资源,并被回收。
            }
        }
Example #2
0
        /// <summary>
        /// 窗体关闭事件
        /// 这里关闭窗体事件,只将窗体隐藏,并执行窗体关闭关联的方法。
        /// </summary>
        private void MarkClosed(object sender, FormClosingEventArgs e)
        {
            if (sender != null)
            {
                MWDockPanel dockForm = sender as MWDockPanel;
                if (dockForm != null)
                {
                    dockForm.Hide();
                    e.Cancel = true;

                    Program.frmMain.m_Menu["mnu" + dockForm.Text].Checked = false;
                }
            }
        }
Example #3
0
        /// <summary>
        /// 返回一个能够用作添加可停靠内容(dockable content)到MainProgram的系统panel
        /// 先创建一个可停靠Form,再在Form里面添加一个Panel,返回这个Panel给调用者。
        /// </summary>
        public System.Windows.Forms.Panel CreatePanel(string caption, System.Windows.Forms.DockStyle dockStyle)
        {
            if (m_Panels.ContainsKey(caption))
            {
                if (m_Panels[caption].Controls["ContentPanel"] != null)
                {
                    return((System.Windows.Forms.Panel)(m_Panels[caption].Controls["ContentPanel"]));
                }
                return((System.Windows.Forms.Panel)(m_Panels[caption].Controls[0]));
            }

            Panel contentPanel = new Panel();

            contentPanel.Name = "ContentPanel";
            contentPanel.Dock = DockStyle.Fill;

            MWDockPanel floatPanel = new MWDockPanel(caption);

            floatPanel.ShowHint = WeifenLuo.WinFormsUI.Docking.DockState.Float;
            floatPanel.Controls.Add(contentPanel);
            floatPanel.FormClosing += new FormClosingEventHandler(MarkClosed);
            floatPanel.Show(Program.frmMain.dckPanel);
            floatPanel.Icon = MapWinGIS.MainProgram.Properties.Resources.MapWinGIS;
            if (dockStyle == DockStyle.None)
            {
                floatPanel.DockState = WeifenLuo.WinFormsUI.Docking.DockState.Float;
            }
            else
            {
                floatPanel.DockState = SimplifyDockstate(dockStyle);
            }

            //我希望创建该窗体时也要创建一个该窗体显示与关闭的菜单
            Program.frmMain.m_Menu.AddMenu("mnu" + caption, "mnuRestoreMenu", (object)null, caption).Checked = floatPanel == null ? false : true;

            m_Panels.Add(caption, floatPanel);
            m_OnCloseHandlers.Add(caption, null);
            return(contentPanel);
        }