Hello,
I am having a hard time deciphering why the IDE will give me a nullReference error when assigning a text string to a textBox.Text control. Following is the code (red highlight is the code where it'd say NullReferenceException unhandled). The debugger says this.TextBox1 = null. I compared this with other codes that I have doing the same thing and in those cases, the debugger would say textBox2 = {Text = ""}.
Any ideas why? In both cases, I right click on it and selected Find All References. I can see that both have the following:
- a line that declares the control
- a line that instantiate the control
- a line that adds the control to the form
- a few lines that set the properties of the control
and
- the line that assigns a string to it.
public partial class InformationBox : Form
{
public InformationBox(string displayInfo)
{
//textBox1.Text = displayInfo;
this.textBox1.Text = "hello";
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
public delegate void ControPass();
public ControPass controlPass;
private void button2_Click(object sender, EventArgs e)
{
if (controlPass != null)
{
controlPass();
}
this.Close();
}
}