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

ERP-易飞
易飞ERP系统运维、二次开发、实施
厦门德仔
        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);
            //    }
            //}
        }
        /// <summary>
        /// 关闭当前页签
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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;
                }
            }
        }
        /// <summary>
        /// 关闭其他页签
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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);
                    
                }
            }
          
        }
        /// <summary>
        /// 关闭全部页签
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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();
            }
        }
        /// <summary>
        /// 双击关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void xtraTabControl_DoubleClick(object sender, EventArgs e)
        {
            XtraTabHitInfo tabHitInfo = ((XtraTabControl)sender).CalcHitInfo(((XtraTabControl)sender).PointToClient(Control.MousePosition));
            ((XtraTabControl)sender).TabPages.Remove(tabHitInfo.Page);
        }

 

 

©️2020 CSDN 皮肤主题: 鲸 设计师: meimeiellie 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值