I have 2 Forms and I can open Form2 from Form1 but when I try to update a label in Form1 from from Form2 the label is not updated. Following is my code of Form1
public Form1()
{
InitializeComponent();
}
void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 'S'|| e.KeyChar == 's')
{
var myForm = new Form2();
myForm.ShowDialog();
myForm.BringToFront();
}
}
public string LabelText
{
get
{
return this.label2.Text;
}
set
{
this.label2.Text = value;
this.label2.Refresh();
}
}
Form 2 code for updating Form1 label is following
Form1 form1Func;
private void updateCounterBtn_Click(object sender, EventArgs e)
{
form1Func = new Form1();
form1Func.LabelText = "09";
form1Func.Refresh();
}
So even though there is no error and using break point I am able to observe that lable2.Text is updated in debugger (using break point and watch) but in Form1 UI lable2 remains same and is not updated. How can I solve my problem?