private void referenceDesk_DoubleClick(object sender, EventArgs e)
{
tabControl1.TabPages.Add(new TabPage("Donkey Kong"));
}
there is no tabControl1.Modifier type command to use, and also can't use
new public TabPage("");
private void referenceDesk_DoubleClick(object sender, EventArgs e)
{
tabControl1.TabPages.Add(new TabPage("Donkey Kong"));
}
there is no tabControl1.Modifier type command to use, and also can't use
new public TabPage("");
The Modifiers
design-time property, controls member creation for the object you are modifying. It is not something you can change later. If you want to add tab pages to a tab control and you want to be able to change them later, define class members for them and assign appropriate access-modifier to them:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private List<TabPage> tabPages;
private void referenceDesk_DoubleClick(object sender, EventArgs e)
{
tabPages = new List<TabPage>();
tabPages.Add(new TabPage("First"));
tabPages.Add(new TabPage("Second"));
foreach (var tab in tabPages)
tabControl1.TabPages.Add(tab);
}
....
}
Designer code is not supposed to be user modified, as it gets re-written by Visual Studio every time you make changes to your form in the designer (as you have discovered).
One way forward it to move the control declaration and initialization to the non designer code file. However, that means your control will no longer appear in the designer.