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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:02:51+00:00 2026-05-14T03:02:51+00:00

Although there are some similar questions I’m having difficulties finding an answer on how

  • 0

Although there are some similar questions I’m having difficulties finding an answer on how to receive data in my form from a class.

I have been trying to read about instantiation and its actually one of the few things that does make sense to me 🙂 but if I were to instantiate my form, would I not have two form objects?

To simplify things, lets say I have a some data in Class1 and I would like to pass a string into a label on Form1. Is it legal to instantiate another form1? When trying to do so it looks like I can then access label1.Text but the label isn’t updating. The only thing I can think of is that the form needs to be redrawn or there is some threading issue that I’m unaware of.

Any insight you could provide would be greatly appreciated.

EDIT: Added some code to help

class Class1
{
    public int number { get; set; }

    public void Counter()
    {
        for (int i = 0; i < 10; i++)
        {
            number = i;
            System.Threading.Thread.Sleep(5000);
        }
    }
}

and the form:

    Class1 myClass = new Class1();

    public Form1()
    {
        InitializeComponent();
        label1.Text = myClass.number.ToString();
    }
  • 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-14T03:02:51+00:00Added an answer on May 14, 2026 at 3:02 am

    Based on the comments in your original post, here are a few ways to do it:
    (this code is based on a Winform app in VS2010, there is 1 form, with a Label named “ValueLabel”, a textbox named “NewValueTextBox”, and a button.

    Also, there is a class “MyClass” that represents the class with the changes that you want to publish.

    Here is the code for the class. Note that I implement INotifyPropertyChanged and I have an event. You don’t have to implement INotifyPropertyChanged, and I have an event that I raise whenever the property changes.

    You should be able to run the form, type something into the textbox, click the button, and see the value of the label change.

    
        public class MyClass: System.ComponentModel.INotifyPropertyChanged
        {
            public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    
            public string AValue
            {
                get
                {
                    return this._AValue;
                }
                set
                {
                    if (value != this._AValue)
                    {
                        this._AValue = value;
                        this.OnPropertyChanged("AValue");
                    }
                }
            }
            private string _AValue;
    
            protected virtual void OnPropertyChanged(string propertyName)
            {
                if(this.PropertyChanged != null)
                    this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    
    

    Example 1: simple databinding between the label and the value:
    So this time, we will just bind the label to an instance of your class. We have a textbox and button that you can use to change the value of the property in MyClass. When it changes, the databinding will cause the label to be update automatically:

    NOTE: Make sure to hook up Form1_Load as the load event for hte form, and UpdateValueButton_Click as the click handler for the button, or nothing will work!

    
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
    
            private MyClass TheClass;
    
            private void Form1_Load(object sender, EventArgs e)
            {
                this.TheClass = new MyClass();
                this.ValueLabel.DataBindings.Add("Text", this.TheClass, "AValue");
            }
    
            private void UpdateValueButton_Click(object sender, EventArgs e)
            {
                // simulate a modification to the value of the class
                this.TheClass.AValue = this.NewValueTextBox.Text;
            }
        }
    
    

    Example 2
    Now, lets bind the value of class directly to the textbox. We’ve commented out the code in the button click hander, and we have bound both the textbox and the label to the object value. Now if you just tab away from the textbox, you will see your changes…

    
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
    
            private MyClass TheClass;
    
            private void Form1_Load(object sender, EventArgs e)
            {
                this.TheClass = new MyClass();
                // bind the Text property on the label to the AValue property on the object instance.
                this.ValueLabel.DataBindings.Add("Text", this.TheClass, "AValue");
                // bind the textbox to the same value...
                this.NewValueTextBox.DataBindings.Add("Text", this.TheClass, "AValue");
            }
    
            private void UpdateValueButton_Click(object sender, EventArgs e)
            {
                //// simulate a modification to the value of the class
                //this.TheClass.AValue = this.NewValueTextBox.Text;
            }
    
    
    

    Example 3
    In this example, we won’t use databinding at all. Instead, we will hook the property change event on MyClass and update manually.

    Note, in real life, you might have a more specific event than Property changed — you might have an AValue changed that is only raised when that property changes.

    
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
    
            private MyClass TheClass;
    
            private void Form1_Load(object sender, EventArgs e)
            {
                this.TheClass = new MyClass();
                this.TheClass.PropertyChanged += this.TheClass_PropertyChanged;
            }
    
            void TheClass_PropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "AValue")
                    this.ValueLabel.Text = this.TheClass.AValue;
            }
    
            private void UpdateValueButton_Click(object sender, EventArgs e)
            {
                // simulate a modification to the value of the class
                this.TheClass.AValue = this.NewValueTextBox.Text;
            }
        }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If it's any help, there is also a similar class in C#'s WebRequest. Although
I have the following code that won't compile and although there is a way
Possible Duplicate: What should a good BugTracking tool be capable of? Although there is
Although I deeply fell in love with the MVVM pattern there seem to be
I wasn't aware of a difference, but a coworker says there is, although he
Although ASP.NET MVC seems to have all the hype these days, WebForms are still
Although somewhat related to this question , I have what I think is a
Although I don't have an iPhone to test this out, my colleague told me
Although I'm specifically interested in web application information, I would also be somewhat curious
Although I do understand the serious implications of playing with this function (or at

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.