[DevExpress]XtraTabControl右键添加关闭当前页、关闭其他页、全部关闭的实现

        private void xtraTabControl_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                xtraTabControl.ContextMenuStrip = null;

                //TreeListHitInfo hInfo = treeList1.CalcHitInfo(new Point(e.X, e.Y));
                //TreeListNode node = hInfo.Node;
                //treeList1.FocusedNode = node;
   
                xtraTabControl.ContextMenuStrip = contextMenuStrip1;
                
            }
        }

        private void xtraTabControl_MouseUp(object sender, MouseEventArgs e)
        {
            //TreeList tree = sender as TreeList;
            //if (e.Button == MouseButtons.Right
            //        && ModifierKeys == Keys.None
            //        && treeList1.State == TreeListState.Regular)
            //{
            //    Point p = new Point(Cursor.Position.X, Cursor.Position.Y);
            //    TreeListHitInfo hitInfo = tree.CalcHitInfo(e.Location);
            //    if (hitInfo.HitInfoType == HitInfoType.Cell)
            //    {
            //        tree.SetFocusedNode(hitInfo.Node);
            //    }

            //    if (tree.FocusedNode != null)
            //    {
            //        popupMenu1.ShowPopup(p);
            //    }
            //}
        }
        /// 
        /// 关闭当前页签
        /// 
        /// 
        /// 
        private void tsmCloseCurrent_Click(object sender, EventArgs e)
        {
            
            string name = xtraTabControl.SelectedTabPage.Text;//得到关闭的选项卡的text
            foreach (XtraTabPage page in xtraTabControl.TabPages)//遍历得到和关闭的选项卡一样的Text
            {
                if (page.Text == name)
                {
                    xtraTabControl.TabPages.Remove(page);
                    page.Dispose();
                    return;
                }
            }
        }
        /// 
        /// 关闭其他页签
        /// 
        /// 
        /// 
        private void tsmCloseOther_Click(object sender, EventArgs e)
        {
            int index = xtraTabControl.SelectedTabPageIndex;//得到关闭的选项卡的索引
            for (int i = xtraTabControl.TabPages.Count - 1; i > 0; i--)
            {
                if (i != index) 
                {
                    xtraTabControl.TabPages.RemoveAt(i);
                    
                }
            }
          
        }
        /// 
        /// 关闭全部页签
        /// 
        /// 
        /// 
        private void tsmCloseAll_Click(object sender, EventArgs e)
        {
            for (int i = xtraTabControl.TabPages.Count-1; i >0; i--)
            {
                xtraTabControl.TabPages.RemoveAt(i);
               // xtraTabControl.TabPages[i].Dispose();
            }
        }
        /// 
        /// 双击关闭
        /// 
        /// 
        /// 
        private void xtraTabControl_DoubleClick(object sender, EventArgs e)
        {
            XtraTabHitInfo tabHitInfo = ((XtraTabControl)sender).CalcHitInfo(((XtraTabControl)sender).PointToClient(Control.MousePosition));
            ((XtraTabControl)sender).TabPages.Remove(tabHitInfo.Page);
        }




你可能感兴趣的:(DevExpress,DevExpress)