1、将标题添加进tabpage中
public void Add_TabPage(string str, Form myForm) //将标题添加进tabpage中
{
if (!this.tabControlCheckHave(this.MainTabControl, str))
{
this.MainTabControl.TabPages.Add(str);
this.MainTabControl.SelectTab((int)(this.MainTabControl.TabPages.Count - 1));
myForm.FormBorderStyle = FormBorderStyle.None;
myForm.TopLevel = false;
myForm.Show();
myForm.Parent = this.MainTabControl.SelectedTab;
}
}
2、看tabpage中是否已有窗体
public bool tabControlCheckHave(TabControl tab, string tabName) //看tabpage中是否已有窗体
{
for (int i = 0; i < tab.TabCount; i++)
{
if (tab.TabPages[i].Text == tabName)
{
tab.SelectedIndex = i;
return true;
}
}
return false;
}
3、添加tabpage标题,并添加嵌套窗体
private void btnService_Click(object sender, EventArgs e)
{
this.Add_TabPage("维护 ", new frmServiceMain());
}
public void Add_TabPage(string str, Form myForm) //将标题添加进tabpage中
{
if (!this.tabControlCheckHave(this.MainTabControl, str))
{
this.MainTabControl.TabPages.Add(str);
this.MainTabControl.SelectTab((int)(this.MainTabControl.TabPages.Count - 1));
myForm.FormBorderStyle = FormBorderStyle.None;
myForm.TopLevel = false;
myForm.Show();
myForm.Parent = this.MainTabControl.SelectedTab;
}
}
2、看tabpage中是否已有窗体
public bool tabControlCheckHave(TabControl tab, string tabName) //看tabpage中是否已有窗体
{
for (int i = 0; i < tab.TabCount; i++)
{
if (tab.TabPages[i].Text == tabName)
{
tab.SelectedIndex = i;
return true;
}
}
return false;
}
3、添加tabpage标题,并添加嵌套窗体
private void btnService_Click(object sender, EventArgs e)
{
this.Add_TabPage("维护 ", new frmServiceMain());
}