Domanda

From the original form form1, I can call this easily

this.tabControl1.SelectedTab.Text

But from form2, I cannot find equivalent method

(form1.Controls["tableLayoutPanel1"].Controls["tabControl1"] as TabControl) 

does not have the SelectedTab method

È stato utile?

Soluzione

Make the modifier on the TabControl's field Public, then you will be able to reference the tab control directly via the field with a reference to Form2.

It will look something like this after you have made the field public.

Form1 frm1 = <A reference to Form1 that you passed in to Form2 somehow>
frm1.TabControl1.SelectedTab.Text = "Changed Text!";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top