I want to add new tabpage from other form in parent form.
My parent form is MainWindow
and this form has TabControl
.
I have child form ChildForm
when i click on child form button i want to add new tabpage in TabControl
from MainWindow
.
I try to create constructor dependency in ChildForm
private MainWindow mainWindow;
public List(MainWindow form)
{
this.mainWindow = form;
}
private void createButton_Click(object sender, EventArgs e)
{
TabPage tabPage = new TabPage("ASD");
mainWindow.MainTabControl.TabPages.Add(tabPage);
}
This will throw System.NullReferenceException
!
I also try to create in MainWindow
accessors witch will return mainTabControl
access in MainWindow
but also not work.
public static TabControl MainTabControl
{
get {
MainWindow self = new MainWindow();
return self.mainTabControl;
}
}
This not work becouse i create new reference and that is problem.
I try 2 examples and both not work and i know whay not work!!!
Anyone know any other opetion how to slove this problem ?