The problem is that i need to access different forms elements from other forms, or for example access MdiContainer form menu from some child windows and do some operations with it. How to correctly implement such feature? I'm using Windows Forms now.
Some sample code below to demonstrate how I tried to do it.
Form1 (is an Mdi container)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void menu2ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 chWin = new Form2(this);
chWin.Show();
}
public void disableMenu()
{
menuStrip1.Enabled = false;
}
}
Form2 (is a child of Form1)
public partial class Form2 : Form
{
private Form1 parent;
public Form2(Form1 parent)
{
InitializeComponent();
MdiParent = parent;
}
private void button1_Click(object sender, EventArgs e)
{
parent.disableMenu();
}
}
And the exception: Object reference not set to an instance of an object
Tried to google on it, but actually nothing helpful for my occasion.
Thanks in advance!