I have the following: I have a GUI with two forms. Form2 is opened via Form1 by a button. Both forms have Textboxes and I want them to communicate with each other (one form can grab the entries of textboxes from another form). What I did now in Form2 is:
private Form1 m_form = null;
public Form2(Form1 f)
{
InitializeComponent();
m_form = f;
}
and for the Textboxes functions like:
public String getLocation()
{
return LocationBox.Text;
}
That works fine. So Form2 can read the entries from Form1. Now I wanted Form1 to read the textbox entries from Form2 and tried the same thing (which is probably wrong):
private Form2 m_form2 = null;
public Form1(Form2 f2)
{
InitializeComponent();
m_form2 = f2;
}
and then some functions like the one I've posted but everytime I want to read a textbox with Form1 which is in Form2 I get "null" and "NullReference" Exception. Where is the error?
EDIT: Ok I solved a part. Adding
Form2 m_form2 = new Form2(this);
m_form2.Show();
solves the problem with the NullReferenceException. Without the line m_form2.Show()
it passes empty strings but now everytime I hit a button the form2 appears.