I have Form1, where there is a TabControl with dynamically added TabPages. Using this code:

newTab.Controls.Add(form3);
form1.mainTabControl.TabPages.Add(newTab);
form1.mainTabControl.SelectedTab = newTab;

I need access from Form3 to another Form3 inside the TabPage.
I Try this code, but it didn't work:

MessageBox.Show(label1.Text); // label text in tabPages[1]
MessageBox.Show(form1.mainTabControl.TabPages[2].Controls[label1.Name].Text); // I need get label text in tabPage[2]
MessageBox.Show(this.Name); // name of Form3

I have added three TabPages.

EDIT

I found fix:

var test = (TabControl) form1.mainTabControl.TabPages[1].Controls["content2axis"].Controls["contentTabControl"];
MessageBox.Show(test.TabPages["result"].Controls["label1"].Text);

or

var yourForm1 = (Content2axis)form1.mainTabControl.TabPages[1].Controls[0];

0 Answers