[英]c# - open form in new thread and pass parameter
Wondering if anyone can help.想知道是否有人可以提供帮助。 I'm trying to open a new form in a new thread and pass it a parameter I can then use to populate a text box in that new form.
我正在尝试在新线程中打开一个新表单并传递一个参数,然后我可以使用它来填充该新表单中的文本框。 Any advice.
任何建议。 I've searched and can't find anything that for this.
我已经搜索过,找不到任何东西。
Thanks谢谢
Nothing special but here is an example:没什么特别的,但这里有一个例子:
Form1 code - Form1 代码 -
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OpenNewForm();
}
private void OpenNewForm()
{
int _paramter1 = 5;
string _parameter2 = "hello";
Thread th = new Thread(() =>
{
Form2 form2 = new Form2(_paramter1, _parameter2);
form2.ShowDialog();
});
th.Start();
}
Form2 code - Form2 代码 -
int Parameter1;
string Parameter2;
public Form2(int parameter1, string parameter2)
{
InitializeComponent();
Parameter1 = parameter1;
Parameter2 = parameter2;
}
private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = Parameter1.ToString();
textBox2.Text = Parameter2;
}
Good Luck!祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.