Reputation: 1231
Sorry for the simple question and also sorry if there is an answer on the site and I couldn't find.
I want to use same textbox in every tab that I use on my form. How can I do that?
Upvotes: 2
Views: 3962
Reputation: 9108
Put the TextBox in the parent control of the TabControl. It can hover over all the rest. You might need to rework the focus traversal though.
Upvotes: 1
Reputation: 112279
Add this to the TabControl
's SelectedIndexChanged
event handler.
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
tabControl1.TabPages[tabControl1.SelectedIndex].Controls.Add(textBox1);
}
Adding a control to one tab page's Controls
collection automatically removes it from the others.
Note: I have tested it by adding two lables on the form above the tab control and added these two lines to the method shown above:
label1.Text = tabControl1.TabPages[0].Controls.Count.ToString();
label2.Text = tabControl1.TabPages[1].Controls.Count.ToString();
Upvotes: 3