在FORM1中,我有一个占位符文本的文本框。点击后,第二个表格(FORM2)会弹出一个可供选择的项目列表。他们选择他们的选择并按下SELECT并且FORM2关闭,并且FORM1的文本框将填充他们从FORM2中的选择。在第二种形式选择后修改文本框的值?
这是我有:
FORM1 -
// Variables
public string ID{ get; set; }
private void openF2_Click(object sender, EventArgs e)
{
FORM2 f2 = new FORM2();
f2.Show();
// updateText(); <-- when called through here, ID is still empty.
}
public void updateText()
{
textBox1.Text = ID;
// textBox1.Refresh(); <-- I thought this would work
}
// Check if it did change
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox1.BackColor = Color.White;
}
FORM2 -
private void btnSelect_Click(object sender, EventArgs e)
{
FORM1 f1= new FORM1();
f1.ID = listOfChoices.SelectedItems[0].SubItems[0].ToString();
f1.updateText();
this.Close();
}
当我步行通过的代码,我看到正在设置ID正确时FORM2调用“updateText()”它将textbox1值设置为ID,并且textChanged函数也会运行,但在GUI上它仍然是空的。
要更新'Form1',不是原来的实例是前手跑的新实例。 –