动态增加一个标签页,且加载一个窗体
DevExpress.XtraTab.XtraTabPage page = new DevExpress.XtraTab.XtraTabPage();
page.Name = "CompanySet";
page.Text = "公司信息";
ViewFrom.frmCompanySet fcs = new ViewFrom.frmCompanySet();
fcs.TopLevel = false; //没设置这个属性的话form窗体在就直接跳到在上层去了
page.Controls.Add(fcs);
this.xtcMain.TabPages.Add(page);
this.xtcMain.SelectedTabPage = page;
fcs.Show();
关闭标签时退出窗体并关闭
private void xtcMain_CloseButtonClick(object sender, EventArgs e)
{
//标签页退出按钮
DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs a = (DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs)e;
string tabPageName = a.Page.Text;
foreach (DevExpress.XtraTab.XtraTabPage xtp in xtcMain.TabPages)
{
if (xtp.Text == tabPageName)
{
try
{
DevExpress.XtraEditors.XtraForm form_main = xtp.Controls[0] as DevExpress.XtraEditors.XtraForm;
form_main.Close();
form_main.Dispose();
xtcMain.TabPages.Remove((a.Page as DevExpress.XtraTab.XtraTabPage));
xtp.Dispose();
return;
}
catch (ArgumentOutOfRangeException aore)
{
MessageBox.Show(aore.Message);
}
}
}
}
private void xtcMain_DoubleClick(object sender, EventArgs e)
{
//仅仅是关闭标签页,而没有退出已载入窗体的资源
xtcMain.TabPages.Remove(this.xtcMain.SelectedTabPage);
}