Salman_Khan
Salman_Khan

Reputation: 89

How can use the label object of one form into other form

actually i just want to set the status of the form each and every time so is there any code so that i can change the label of one form from the other form

Upvotes: 1

Views: 53

Answers (1)

Uwe Keim
Uwe Keim

Reputation: 40736

You have to manually pass the value from form 1 to form 2.

E.g. if your Form1 shows Form2, you could do:

public partial class Form1: Form
{
    // ...

    private void button2_Click( object sender, EventArgs e )
    {
        using ( var form2 = new Form2() )
        {
            form2.LabelValue = this.label1.Text;
            form2.ShowDialog(this);
        }
    }
}

Write a public property LabelValue in Form2 that maps to the label in Form2.

Upvotes: 1

Related Questions