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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:57:17+00:00 2026-05-16T16:57:17+00:00

I had a confusion let me explain it in brief. I have a form

  • 0

I had a confusion let me explain it in brief.
I have a form i placed one textbox and a command button.
and I have one plain class.

class1 code.

class Class1
{
    string s = "hi";
    Form1 form1 = new Form1();
    public void cl()
    {
        form1.textBox1.Text = s;

    }


}

form1 code

private void button1_Click(object sender, EventArgs e)
    {
        Class1 class1 = new Class1();
        class1.cl();
    }

what my program should do is when i click on the button the text in the textbox should become “hi”.
My error is when I click the button nothing happens.

  • 1 1 Answer
  • 6 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-16T16:57:17+00:00Added an answer on May 16, 2026 at 4:57 pm

    You are creating a new Form1 instance, so you are changing the text on a form that’s not being displayed, nor is the form where the button was actually clicked. You could do what you want by passing the form as a parameter to the method call:

    class Class1
    {
        string s = "hi";
        public void cl(Form1 form1)
        {
            form1.textBox1.Text = s;
    
        }  
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
        Class1 class1 = new Class1();
        class1.cl(this);
    }
    

    But it might be better form (depends on the actual case) to do the changes on form appearance only in the form code itself, using helper classes to generate the data only, for example:

    class Class1
    {
        string s = "hi";
        public string cl()
        {
             return s;
        }  
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
        Class1 class1 = new Class1();
        this.textBox1.Text = class1.cl();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had designed a Stack wrapper class. My confusion is, should I be using
this is something I have always had confusion about I never can seem to
Had to download Command Line Tools from Apple to get make to work, but
Had a good read through similar topics but I can't quite a) find one
Had a problem with the recursive conflictCheck() method. That seems fine now. I have
Had this working; at one stage. The problem is the following text is now
I had a class that had lots of methods: public class MyClass { public
Like most people new to Git, I've had my share of confusion trying to
Mary had a little form, and its fields where labeled just so. Whenever an
I realized that I had some confusion regarding the value of a dereferenced pointer,

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.