/// <summary>
 /// 关闭窗体移除节点
 /// </summary>
 /// <param name="currentForm">当前窗体</param>
 public static void RemovePage(DS.MSClient.UIModule.BaseUserControl currentForm = null)
 {
     if (currentForm != null && currentForm.Parent != null && currentForm.Parent is Form)//父容器是窗体
     {
         ((Form)currentForm.Parent).Close();
     }
     else//父容器是tabpage
     {
         if (Program.TabcMain.SelectedTabPage != null && Program.TabcMain.SelectedTabPageIndex != 0)
         {
             int currentSelectIndex = Program.TabcMain.SelectedTabPageIndex;
             if (Program.TabcMain.SelectedTabPage.Tag != null)
             {
                 FormFindMin(ValueConvert.ToString(Program.TabcMain.SelectedTabPage.Tag));
                 //移除工作列表节点
                 var node = Program.ArrHistoryNode.Find(m => m.guid == Program.TabcMain.SelectedTabPage.Tag.ToString() && m.Array == 3);
                 if (node != null)
                 {
                     if (!node.isForm && Program.HtTreeListHistory.ContainsKey(node.Pid + "列表"))//如果不是编辑窗口,移除防止重复添加列表的key
                     {
                         Program.HtTreeListHistory.Remove(node.Pid + "列表");
                     }
                     Program.ArrHistoryNode.Remove(node);
                     //判断是否需要移除父节点
                     var parentnode = Program.ArrHistoryNode.FindAll(m => m.Pid == node.Pid);
                     if (parentnode == null || parentnode.Count() == 0)
                     {
                         var _node = Program.ArrHistoryNode.Find(m => m.Fid == node.Pid);
                         Program.ArrHistoryNode.Remove(_node);
                     }
                     Program.TreeListHistory.RefreshDataSource();
                     Program.TreeListHistory.Refresh();
                 }
             }
             DevExpress.XtraTab.XtraTabPage selectedTabPage = Program.TabcMain.SelectedTabPage;
             Program.TabcMain.TabPages.Remove(Program.TabcMain.SelectedTabPage);
             if (selectedTabPage != null)
             {
                 foreach (System.Windows.Forms.Control tempCtrl in selectedTabPage.Controls)
                 {
                     if (tempCtrl is DevExpress.XtraGrid.GridControl)//移除grid,触发保存grid布局样式事件(此处去掉,grid样式将不能保存)
                     {
                         selectedTabPage.Controls.Remove(tempCtrl);
                     }
                 }
                 selectedTabPage.Dispose();
             }
             if (currentSelectIndex <= Program.TabcMain.TabPages.Count - 1)
             {
                 Program.TabcMain.SelectedTabPageIndex = currentSelectIndex;
             }
             else
             {
                 Program.TabcMain.SelectedTabPageIndex = currentSelectIndex - 1;
             }
         }
     }
 }
Example #2
0
        private void xtraTabControl1_CloseButtonClick(object sender, EventArgs e)
        {
            DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs arg = e as DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs;
            DevExpress.XtraTab.XtraTabPage page = arg.Page as DevExpress.XtraTab.XtraTabPage;

            page.Controls.Clear();
            this.xtraTabControl1.TabPages.Remove(page);
            page.Dispose();
        }