标签:os ar for sp on c ad ef new
C#—Dev XtraTabControl动态增加Tab和关闭选项卡方法,有需要的朋友可以参考下。
记录一下以免以后忘了
添加using DevExpress.XtraTab;
双击listview增加相应的tabpage,禁止重复添加:
private void listView_index_MouseDoubleClick(object sender, MouseEventArgs e) { if (listView_index.SelectedItems.Count > 0) { ListViewItem lvi = listView_index.SelectedItems[0];//得到选中的项 string name = lvi.Text; //判断是否已创建过 foreach (XtraTabPage page in xtraTabControl.TabPages) { if (page.Text == name) { xtraTabControl.SelectedTabPage = page;//显示该页 return; } } //增加tabpage XtraTabPage xpage = new XtraTabPage(); xpage.Name = name; xpage.Text = name; xpage.Controls.Add(ListView_Tec);//添加要增加的控件 xtraTabControl.TabPages.Add(xpage); xtraTabControl.SelectedTabPage = xpage;//显示该页 } }
若要tabpage显示关闭按钮,把xtraTabControl的ClosePageButtonShowMode属性设为InAllTabPageHeaders;若想要首页不显示关闭按钮:
xtraTab_index.ShowCloseButton = DevExpress.Utils.DefaultBoolean.False;//首页不显示关闭按钮
添加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; } } }
C#—Dev XtraTabControl动态增加Tab和关闭选项卡方法
标签:os ar for sp on c ad ef new
原文地址:http://www.cnblogs.com/yeye518/p/3981159.html