I have a tab control on my form. I prompt the user through user input (using the Visual Basic library) how many pockets does the header have. The number in the textbox generates that many number of tabs.
Question
How do I add textboxes when new tabs are generated? Since the number is unknown until I tell it, it wouldn't make sense to just add textboxes to the designer for example.
What I have
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string input = Microsoft.VisualBasic.Interaction.InputBox("How many pockets does the header have?", "Pocket Count", "",-1,-1);
for (int i = 1; i < Convert.ToInt32(input) + 1; i++)
{
tabControl1.TabPages.Add("Pocket" + i);
TextBox txt = new TextBox();
txt.Name = tabControl1.Name;
}
tabControl1.TabPages.Add("Next");
}
Tab Selecting Event:This explains the Tab Selecting Event, you can then use this to dynamically generate the textbox you need on the tab that is being selected.
How to dynamically add a textbox: This explains how to add a control at runtime and even provides a textbox example.
If you take both of these articles together you might end up with something like the below, though you will definitely want to tailor this to your specific application
private void TabControl1_Selecting(Object sender, TabControlCancelEventArgs e)
{
TextBox dynamictextbox = new TextBox();
dynamictextbox.Text = "(Enter some text)";
dynamictextbox.ID = "dynamictextbox";
(TabControl)sender.controls.Add(dynamictextbox)
}
}
This isn't meant to be a complete example but to illustrate how it might work. In your case you will have to wire up the Selecting event in code for each dynamic tab