When a button is clicked in Dialog window, the program must run Test()
which is defined in the Main window.
Main
namespace Program
{
public partial class Main : Form
{
private __Dialog _Dialog = null;
public Main()
{
InitializeComponent();
using (this._Dialog = new __Dialog())
{
_Dialog.ShowDialog(this);
}
}
public void Test()
{
//
}
}
}
Dialog
namespace Program
{
public partial class __Dialog : Form
{
public Main p;
public __Dialog()
{
InitializeComponent();
}
private void Button_Click(object sender, EventArgs e)
{
p.Test();
}
}
}
I get this error message:
NullReferenceException was unhandledAn unhandled exception of type 'System.NullReferenceException' occurred in Program.exe
System.NullReferenceException {"Object reference not set to an instance of an object."}
What can be done to fix it?