Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 240047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:38:04+00:00 2026-05-11T20:38:04+00:00

I know this is probably a very newbish question, so I apologize. I am

  • 0

I know this is probably a very newbish question, so I apologize.

I am trying to access the Text property of a label on Form1 from another form, MaxScore.

When I click the Ok button on MaxScore, I want to set Form1’s myGameCountLbl.Text to Form1’s variable, max by using max.ToString().

Here is my code in the OK button event of MaxScore:

private void okBtn_Click(object sender, EventArgs e)
{
    Form1.myGameCountLbl.Text = Form1.max.ToString();
    Form1.compGameCountLbl.Text = Form1.max.ToString();
}

But when I go to compile it, I get the error:

An object reference is required for the 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 the two labels are pubic as well.

Thanks!

This is the code in my constructor (thank you lassevk for the code!):

public Form1()
{
    //initialize vars
    myHp = 100;
    compHp = 100;
    youWon = 0;
    compWon = 0;
    money = 100;
    canCompAttack = true;
    gameOver = false;

    //show HowToPlay Dialogue
    HowToPlay howToPlay = new HowToPlay();
    howToPlay.ShowDialog();

    using (MaxScore maxScore = new MaxScore())
    {
        maxScore.MainForm = this;
        maxScore.ShowDialog();
    }

    InitializeComponent();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:38:04+00:00Added an answer on May 11, 2026 at 8:38 pm

    Is by any chance Form1 the name of the class?

    You need to have a reference to an instance of the form class.

    Since okBtn is not on the same form, you need to give the MaxScore form a reference to the Form1 instance.

    For instance, you can add this to your MaxScore form:

    public Form1 MainForm { get; set; }
    

    And then in your okBtn_Click method, you’ll write this:

    private void okBtn_Click(object sender, EventArgs e)
    {
        MainForm.myGameCountLbl.Text = MainForm.max.ToString();
        MainForm.compGameCountLbl.Text = MainForm.max.ToString();
    }
    

    and then when you’re constructing MaxScore from Form1 (I’m assuming that’s what you’re doing):

    using (MaxScore scoreForm = new MaxScore())
    {
        scoreForm.MainForm = this;
        scoreForm.ShowDialog();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is probably a very simple question but how would I do
I know this is probably a very beginner question that I just can't seem
This is probably a very basic question and I know how to do it
This probably very easy when you know how, but I don't :) I'm trying
I know this is probably a very obtuse question, but do entities which represent
I know this is probably a very simple question, but I can't seem to
I know this question is probably very basic, but I am a beginner so
I know this is probably a really amateur question, but I can't figure this
i know this is probably a stupid question and i know js scope questions
I know this is probably a question that is asked a ton on here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.