窗体A、B,A中有listbox1,B中有listbox2和按钮1。
首先打开窗体A,通过A上的另外一个按钮打开窗体B,窗体A不关闭;
现在在窗体B的listbox2中输入字符串S,点击按钮1,需要窗体A的listbox1中显示出S,如何实现?
不能重新生成窗体A。
需要核心代码!
首先打开窗体A,通过A上的另外一个按钮打开窗体B,窗体A不关闭;
现在在窗体B的listbox2中输入字符串S,点击按钮1,需要窗体A的listbox1中显示出S,如何实现?
不能重新生成窗体A。
需要核心代码!
#region Form1
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.a += new Form2.aa(getstr);
form2.Show();
}
void getstr(string str)
{
listBox1.Items.Add(str);
}
#endregion
#region Form2
public delegate void aa(string str);
public event aa a; private void button1_Click(object sender, EventArgs e)
{
this.a(textBox1.Text);
}
#endregion