C#—Dev XtraTabControl动态增加Tab和关闭选项卡方法

点击关闭按钮关闭 

若要tabpage显示关闭按钮,把xtraTabControl的ClosePageButtonShowMode属性设为InAllTabPageHeaders;若想要首页不显示关闭按钮:

添加xtraTabControl的CloseButtonClick事件:

 

private void xtraTabControl_CloseButtonClick(object sender, EventArgs e)//关闭选项卡方法  
{  
    DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs EArg = (DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs)e;  
    string name = EArg.Page.Text;//得到关闭的选项卡的text  
    foreach (XtraTabPage page in xtraTabControl.TabPages)//遍历得到和关闭的选项卡一样的Text  
    {  
        if (page.Text == name)  
        {  
            xtraTabControl.TabPages.Remove(page);  
            page.Dispose();  
            return;  
        }  
    }  
} 

2.双击标签关闭

得到你现在鼠标所在的Page

XtraTabPage CurrentPage = new XtraTabPage();  
  
private void xtraTabControl_HotTrackedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)  
{  
    try  
    {  
        CurrentPage = e.Page;  
    }  
    catch (System.Exception ex)  
    {  
        CurrentPage = null;  
    }  
}  
private void xtraTabControl_MouseDoubleClick(object sender, MouseEventArgs e)  
{  
    if (CurrentPage != null)  
    {  
        xtraTabControl.TabPages.Remove(CurrentPage);  
        CurrentPage.Dispose();  
    }  
}  

来自:http://blog.csdn.net/hyj_13/article/details/20314463

posted @ 2017-08-01 14:42  荣码一生  阅读(409)  评论(0编辑  收藏  举报