Reputation: 11
I have a form1 with a menustrip and tabcontrol that form2 opened in tabpage1 . I want to run a public function from form2 when i click on a ToolStripMenuItem . form2 opened with this code :
form2 sar = new form2(usrnm);
sar.TopLevel = false;
sar.WindowState = FormWindowState.Maximized;
sar.FormBorderStyle = FormBorderStyle.None;
TabPage tb = new TabPage();
tb.Controls.Add(sar);
sar.Parent = tb;
tabControl1.TabPages.Add(tb);
sar.Show();
tabControl1.SelectTab(tb);
tabControl1.SelectedTab.Text = "Oncor Daily";
I have a public void savenewform()
function in form2 and i want to run that . I don't know how can i do this .
Upvotes: 0
Views: 97
Reputation: 764
Store a reference to 'sar' somewhere on Form1, then your ToolStripMenuItem can check that the 'somewhere' is non-null, then use it as a reference to the form. Since the reference will be of type 'form2' it will have your public function available.
If you want to pull this trick for other form types, you may need to make an interface for them, so you can treat them as 'iDavesSubForm' rather than 'Form2'.
Upvotes: 0