I'm not doing any of this in the constructor. A simple case is: I have 2 forms Form1 has a public string, myString, initialised with "ABCDEF". It also has a button that when clicked loads Form2: private void button1_Click(object sender, System.EventArgs e) { Form2 frm = new Form2(); frm.Show(); }
Form2 has a label on it, in the label's 'Click' event I try to set it's Text with the following: void label1_Click(object sender, System.EventArgs e) { label1.Text = ((Form1)this.ParentForm).myString; }
This causes the NullReferenceException and when I highlight 'this.ParentForm', it shows as Why?
A
AWoodgate
@AWoodgate
Posts
-
ParentForm and a null reference