Reputation: 708
currently i am using a handmade Messagebox build by the idea of:
Communicate between two windows forms in C#
this solution put as base of a section of my project i found out it is not reacting straight away when i use this code:
//Form 1
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Framerate = "Test1";
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this);
frm.Show();
label2.Text = Framerate; // this statement is delayed / working too soon
}
public string Framerate
{
get { return label1.Text; }
set { label1.Text = value; }
}
}
in Form2 i am changing Framerate. when debugging this project i found out FrameRate is changing in Form2 and also on Form1 but when i run it further
label2.Text = Framerate
is not changed. my question, why is it not changing right away, and what can i do to get it to change right away
edit:
it seems it runs whole button1_click before showing Form2.
Label1.Text is changed when i' m closing Form2 (bacause of the get / set stuff) but that is too late for my application
EDIT:
after some messing arround i found an answer myself, maybe not nice but working for my application:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Framerate = "Test1";
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this);
frm.Show();
}
private void test()
{
label2.Text = Framerate;
}
public string Framerate
{
get { return label1.Text; }
set
{
label1.Text = value;
test();
}
}
}
everyone thanks for trying to help me.
Upvotes: 0
Views: 126
Reputation: 708
after some messing arround i found an answer myself, maybe not nice but working for my application:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Framerate = "Test1";
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this);
frm.Show();
}
private void test()
{
label2.Text = Framerate;
}
public string Framerate
{
get { return label1.Text; }
set
{
label1.Text = value;
test();
}
}
}
Upvotes: 0
Reputation: 81620
You need to either include a reference to Form1.Label2 in your Form2, or have Form2 raise an event that Form1 is listening to for the Framerate change.
Upvotes: 1