Changing a label's text in another form in C#?

c#, winforms

Solution

You need to expose your label or its property.

In form 2:

public string LabelText
{
    get
    {
        return this.labelX1.Text;
    }
    set
    {
        this.labelX1.Text = value;
    }
}

Then you can do:

form2 frm2 = new form2();
frm2.LabelText = this.button1.text;

Problem

I have a label called LabelX1. This is on form2. On form1, i have a button. I want the button's text to be transferred to the other form's label. I have tried ``` form2 frm2 = new form2(); frm2.labelX1.Text = this.button1.text; ``` But it does not work. Is there an easy, straight forward way of doing this?

Original source