原创

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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://david.blog.csdn.net/article/details/50717820
        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);
        }




文章最后发布于: 2016-02-22 16:50:41
展开阅读全文
0 个人打赏
私信求帮助

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 鲸 设计师: meimeiellie

分享到微信朋友圈

×

扫一扫,手机浏览