Hello everyone,
In the button click even handler of Form1, I want to create Form2. Here is my code,
even handler of button1 of Form1
// button1 belongs to Form1
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2("www.google.com");
form2.ShowDialog();
}
Form2 contructor
public Form2 (string str)
{
InitializeComponent();
address = str;
button2.Text = str; // button2 belongs to Form2
}
public Form2()
{
InitializeComponent();
}
My question and concern is, button 1 event handler is executed by Form1's UI thread, and if I create new Form2 inside the Form1 UI thread, and use the UI thread to set Form2's UI element (button2.Text), is that legal? My understanding is each Form has its owner UI thread and UI elements (e.g. button) should be processed only by the forms individual owner thread? If my code is wrong, appreciated if anyone could show me what is the elegant way to creat another Form inside event handler of the current form and pass parameters.
I am using VSTS 2008 + C# + .Net 2.0.
thanks in advance, George