I have a user control that is added to tab page. Problem is it works fine the first time a new tab is added but when i click button to add new tab page again, the user controls doesnt appear on any tab including the first tab also...
public void addnewtab()
{
UserControl1 myUserControl;
myUserControl = new UserControl1();
myUserControl.Dock = DockStyle.Fill;
myTabPage.Controls.Add(myUserControl);
tabControl1.TabPages.Add(myTabPage);
}
this is my code. Please help.
It is not clear where you get myTabPage. You need to create new tabpage inside the method and add usercontrol into it.
public void AddNewTab()
{
UserControl1 myUserControl = new UserControl1();
myUserControl.Dock = DockStyle.Fill;
TabPage myTabPage = new TabPage();//Create new tabpage
myTabPage.Controls.Add(myUserControl);
tabControl1.TabPages.Add(myTabPage);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With