swagger
swagger

Reputation: 37

How To Update Data Between Win Forms c#

I Have to pass text value from txtform1.Text on Form1 to txtform2 on Form2.

I know How to pass value.I used following code.

Code In Form1 to open Form2 By Button Click

private void button2_Click(object sender, EventArgs e)//send message to contact chat
    {
        string value = txtform1.Text;
        Form2 f = new Form2(value);
        f.Show();
    }

code in Form2 to get the value

public Form2(string value)
    {
        InitializeComponent();
         txtform2.Text = value;
    }

But this way the value can not be updated .

what i want is to update txtform2.text whatever i type in txtform1.text.

Upvotes: 0

Views: 68

Answers (1)

bowlturner
bowlturner

Reputation: 2016

Form2 will need to have a public property

public string TxtForm2 
{
 set { txtform2.Text = value; }
}

you can add a get as well. Then you can use

Form2.TxtForm2 = 'Some new value';

Upvotes: 1

Related Questions