I know this is probably a very newbie, so I apologize.
I am trying to access the Text property of a label on Form1 from another MaxScore form.
When I click the Ok button on MaxScore, I want to set Form1 myGameCountLbl.Text to the Form1 max variable using max.ToString ().
Here is my code in the OK MaxScore button event:
private void okBtn_Click(object sender, EventArgs e)
{
Form1.myGameCountLbl.Text = Form1.max.ToString();
Form1.compGameCountLbl.Text = Form1.max.ToString();
}
But when I am going to compile it, I get an error message:
An object reference is required for a non-static field, method, or property "Towergame_2.Form1.myGameCountLbl"
I get the same error for Towergame_2.Form1.max and Towergame_2.Form1.compGameCountLbl.
Not quite sure how to fix this. Max is a public variable, and these two labels are also pubic.
Thanks!
( lassevk !):
public Form1()
{
myHp = 100;
compHp = 100;
youWon = 0;
compWon = 0;
money = 100;
canCompAttack = true;
gameOver = false;
HowToPlay howToPlay = new HowToPlay();
howToPlay.ShowDialog();
using (MaxScore maxScore = new MaxScore())
{
maxScore.MainForm = this;
maxScore.ShowDialog();
}
InitializeComponent();
}