Updating label in another form (C#)
Posted
by
cthulhu
on Stack Overflow
See other posts from Stack Overflow
or by cthulhu
Published on 2010-12-26T10:49:55Z
Indexed on
2010/12/26
10:53 UTC
Read the original article
Hit count: 168
c#
I want to update label of Form1 from Form2. So here's what I have:
// Form1
public string Label1
{
get { return this.label1.Text; }
set { this.label1.Text = value; }
}
// Form2
private void button1_Click(object sender, EventArgs e)
{
Form1 frm1 = new Form1();
frm1.Label1 = this.textBox1.Text;
this.Close();
}
So the above code doesn't work. However, when I add the following:
frm1.Show();
after
this.Close();
in Form2 code, the Form1 is being opened again (two windows). But I want it to update in the same window so I suggest this.Close() is unnecessary.
© Stack Overflow or respective owner