Reputation: 135
I am trying to add a TabPage and inside it a Textbox. The problem is if I have more TabPages the content of the TextBox is always the last added and not the selected TabPage.
EDIT 3 //
public partial class Form1 : Form
{
int tabcount = 0;
TextBox TextE;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Create a new textbox to add to each control
TextE = new TextBox();
// Fill the tabpage
TextE.Dock = DockStyle.Fill;
TextE.Multiline = true;
// Create new tab page and increment the text of it
TabPage tab = new TabPage();
tab.Text = "Tab" + tabcount.ToString();
// Add Textbox to the tab
tab.Controls.Add(TextE);
// Add tabpage to tabcontrol
tabControl1.Controls.Add(tab);
tabcount++;
}
private void button2_Click(object sender, EventArgs e)
{
// Text content to messagebox...
MessageBox.Show(TextE.Text);
}
}
Upvotes: 0
Views: 1583
Reputation: 6958
Try naming the tabs with a number index("Tab01","Tab02", etc.) then cast the current tab as Scintilla TextEditor
. Don't get confused by the object name and the Name property. The controls collection uses the name property as an index key. so even though you have objects you've declared with the same name, as long as the name property is different you can add them.
For instance
Scintilla NewTextEditor = new Scintilla();
NewTextEditor.Name = "tab" + (this.Controls.OfType<Scintilla>.Count + 1).ToString("00");
this.Controls.Add(NewTextEditor);
this will add a new control change the name property so it can be added.
Then Assuming you have a way of determining the current tab
Scintilla TextEditor = CurrentTab;
Upvotes: 1