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

Related Questions

For example, I have an ASP.NET form that is called by another aspx: string
I have a form in which people will be entering dollar values. Possible inputs:
I have a set of textboxes on a form, called sm1, sm2 etc, and
I have subclassed Form to include some extra functionality, which boils down to a
I have a datagridview which we will call dataGridViewExample. My object (the uncommon datatypes
I have form area in my view. If I click button A , I
I have form that displays several keywords (standard set of choice lists that changes
I have a form in C# that has a button that, when clicked, I
I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have a form with some radio buttons that are disabled by default. When

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.