Hi there, Whenever I run my program, I get: NullReferenceException was unhandled, Object Reference not set to an instance of an object.
When I start the program, I have a form appear called MaxScore where the user enters the max score and presses OK. In the OK event, I call a method from MainForm to update the maxGameCountLabel on MainForm with the value entered for the max score, as a parameter.
When I press ok, I get the NullReferenceException at
myGameCountLbl.Text = maxGames.ToString();
of my maxGameCountLblUpdate method.
Here is the maxGameCountLblUpdate method code which resides in MainForm:
//Update game count label
public void maxGameCountLblUpdate(decimal maxGames)
{
maxGames = decimal.ToInt32(maxGames);
myGameCountLbl.Text = maxGames.ToString();
compGameCountLbl.Text = maxGames.ToString();
}
Here is my OK Button event on MaxScore:
private void okBtn_Click(object sender, EventArgs e)
{
MainForm.maxGameCountLblUpdate(max);
}
Note, I have set
public Form1 MainForm { get; set; }
in MaxScore
And I create MaxScore in MainForm with:
using (MaxScore scoreForm = new MaxScore())
{
scoreForm.MainForm = this;
scoreForm.ShowDialog();
}
I can't get this to work.. I have tried many things.. Thanks!
EDIT: After adding a breakpoint at myGameCountLbl.Text = maxGames.ToString(); myGameCountLbl appears to be coming up as null... Im sorry for being a newb... How do I fix this? maxGames, indeed, does come up as 1, so that is not the problem