Changing a label's text in another form in C#?
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;
You could modify the constructor of Form2 like this:
public Form2(string labelText)
{
InitializeComponent();
this.labelX1.Text = labelText;
}
then create Form2 passing in the text:
Form2 frm2 = new Form2(this.button1.text);
inside form2 write this
public void ChangeLabel(string s)
{
labelX1.Text = s;
}
then where you create Form 2 do this
form2 frm2 = new form2();
frm2.ChangeLabel(this.button1.text);