XtraTabControl
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了XtraTabControl相关的知识,希望对你有一定的参考价值。
添加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; } } }
public int GetTabName(string value)
{
int count = -1;
for (int i = 0; i < xtraTabControl1.TabPages.Count; i++)
{
if (xtraTabControl1.TabPages[i].Name == value)
{
return i;
}
}
return count;
}
private void button1_Click(object sender, EventArgs e)
{
int i = GetTabName("1"); //查询Tab控件中是否有此 name属性
if (i != -1)
{
xtraTabControl1.SelectedTabPageIndex = i;
return;
}
TextBox Mytextbox = new TextBox(); //TextBox
DevExpress.XtraTab.XtraTabPage tp = new DevExpress.XtraTab.XtraTabPage();
tp.Controls.Add(Mytextbox);
tp.Text = "1";
tp.Name = "1";
xtraTabControl1.TabPages.Add(tp);
xtraTabControl1.SelectedTabPage = tp;
}
private void button2_Click(object sender, EventArgs e)
{
int i = GetTabName("2"); //查询Tab控件中是否有此 name属性
if (i != -1)
{
xtraTabControl1.SelectedTabPageIndex = i;
return;
}
TextBox Mytextbox = new TextBox(); //TextBox
DevExpress.XtraTab.XtraTabPage tp1 = new DevExpress.XtraTab.XtraTabPage();
tp1.Controls.Add(Mytextbox);
tp1.Text = "2";
tp1.Name = "2";
xtraTabControl1.TabPages.Add(tp1);
xtraTabControl1.SelectedTabPage = tp1;
}XtraTabControl
以上是关于XtraTabControl的主要内容,如果未能解决你的问题,请参考以下文章