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 7859471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:54:59+00:00 2026-06-02T21:54:59+00:00

When using a basic form application in C# I am having trouble accessing the

  • 0

When using a basic form application in C# I am having trouble accessing the variabels within it.

So with in the form class I have

public partial class pingerform : Form 
{
  ..
  ..

  private System.Windows.Forms.TextBox textBox2;

  public string textBox2Text
  {
      get { return textBox2.Text; }
      set { textBox2.Text = value; }
  }

And then in the main application I have

Application.Run(new pingerform());
...
...

pingerform.textBox2Text.text() = str;

but I am told that there is no object reference.

Error 1
An object reference is required for the non-static field,
method, or property
‘pingerform.textBox2Text.get’ C:\Users\aaron.street\Documents\Visual
Studio 11\Projects\PingDrop\PingDrop\Program.cs 54 21 PingDrop

So I thought I would make the pinger form class static but it wont let me do this?

Error 1
Cannot create an instance of the static class
‘PingDrop.pingerform’ C:\Users\aaron.street\Documents\Visual Studio
11\Projects\PingDrop\PingDrop\Program.cs 21 29 PingDrop

How can I access the forms properties with out creating a specific instance of the form,

I have a background thread running that I want to update a text filed with in the form at regular intervals?

Cheers

Aaron

  • 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-06-02T21:55:00+00:00Added an answer on June 2, 2026 at 9:55 pm

    You have no choice but to create new instance and either pass it as parameter to the thread, or store it as member of your main Program class.

    Example for the second option:

    private static pingerform myPingerform = null;
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        myPingerform = new pingerform();
        Thread thread = new Thread(new ThreadStart(UpdateTextBox));
        thread.Start();
        Application.Run(myPingerform);
    }
    
    private static void UpdateTextBox()
    {
        while (true)
        {
            myPingerform.textBox2.Text = DateTime.Now.Ticks.ToString();
            Thread.Sleep(1000);
        }
    }
    

    And don’t forget to change the textbox to be public.

    Note: this is simple working solution to the simple case of one background thread accessing the textbox. If you have more threads accessing it, this will break. For best practice methods that require some more work, please read this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic question about using WndProc in my form application. I want
I have a basic form that I'm using for member registration. I'm using the
I am using visual basic for coding. In my form I have a delete
I'm using Visual Basic 2010 Express. I have a form that can be minimized.
I'm having trouble with a basic HttpWebRequest in a WP7 application. As soon as
I'm creating a basic form with ajax submit using jquery framework. This is my
I am using basic code to highlight the text within a text field when
I have a self-hosted WCF app using Basic HTTP Binding, no SSL, running in
I have a data mart mastered from our OLTP Oracle database using basic Materialized
I have a very basic application that has buttons in a toolstrip. When a

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.