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.
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:
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: