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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:53:31+00:00 2026-05-13T15:53:31+00:00

I have a form called Form1.cs, which calls a class which we will refer

  • 0

I have a form called “Form1.cs”, which calls a class which we will refer to as “Class1.cs”, as well as another form called “Form2.cs”. A subroutine in Class1 needs to update a textbox in Form2 if that form is open. The text needs to appear after it is appended to the current text in the textbox so that is updates in real time. I can’t figure out how to make this work. I have tried many things and they don’t give me errors but they don’t write the text into the textbox either.

Per request here is my current code. Keep in mind that this is the test project for figuring this out before implementing it into the real one.

Code in Form1.cs

namespace Test
{
    public partial class Form1 : Form
    {
        Form2 cs_form2 = new Form2();
        Class1 cs_class1 = new Class1();
        public Form1()
        {
            InitializeComponent();

        }
        public void button1_Click(object sender, EventArgs e)
        {
            cs_class1.Writelog();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            cs_form2.Show();
        }
        public void writeToTextbox()
            {
                i = 0;
                while(i<=10)
                {
                    cs_form2.testTextBox.AppendText("still works");
                    i++;
                }
            }
    }
}

Code in Form2.cs

namespace Test
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void clear_Click(object sender, EventArgs e)
        {

            testTextBox.Text = "";
        }

        public void AppendText()
        {
            testTextBox.AppendText("asklvhslieh");
        }
    }
}

Code in Class1

namespace Test
{
    class Class1
    {
        Form2 cs_form2 = new Form2();

        public void Writelog()
        {
            cs_form2.testTextBox.AppendText("asg");
        }
    }
}
  • 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-13T15:53:31+00:00Added an answer on May 13, 2026 at 3:53 pm

    EDIT: By writing new Form2(), your code in Class1 is creating a new instance of Form2.
    This instance does not have anything to do with the other instance created in Form1 (also by writing new Form2()) which is actually visible.
    You need to give Class1 the existing instance of Form2, perhaps using a static property (as described below).


    Pre-Edit

    To append text to the textbox, you should call the AppendText method.

    To do that outside of Form2, you should make a public method on Form2 that calls AppendText.

    For example:

    partial class Form2 : Form {
        ...
        public void AppendMyText(string text) {
            myTextbox.AppendText(text);
        }
        ...
    }
    

    To call this method in Class1, you’ll need a reference to a Form2 object.
    If you only have one Form2 at a time, you can make a static property, like this:

    partial class Form2 : Form {
        static Form2 instance;
        public static Form2 Instance { get { return instance; } }
    
        protected override void OnShown(EventArgs e) {
            base.OnShown(e);
            instance = this;
        }
        
        protected override void OnClosed(EventArgs e) {
            base.OnClosed(e);
            instance = null;
        }
    

    In Class1 (or anywhere else), you can then write

    if (Form2.Instance != null)
        Form2.Instance.AppendMyText(someString);
    

    Note that you need to do this on the UI thread; if you’re running on a background thread, you can call BeginInvoke.

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

Sidebar

Ask A Question

Stats

  • Questions 294k
  • Answers 294k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The java.io.File and consorts acts on the local disk file… May 13, 2026 at 6:34 pm
  • Editorial Team
    Editorial Team added an answer Just parse the entire starting number into an integer and… May 13, 2026 at 6:34 pm
  • Editorial Team
    Editorial Team added an answer You can retrieve the source HTML using: strHTML = myIE.Document.body.innerHTML May 13, 2026 at 6:34 pm

Related Questions

I made a program in which I wanted to manually update the Data Grid
I've created a simple solution with 2 projects. The 1st project (class library) contains
Here's the situation: I'm developing a simple application with the following structure: FormMain (startup
I designed a class which creates XML for a POST in order to call
I have simple chat program using WCF service. One service use for server and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.