现在有两个窗体,窗体1和窗体2,单击窗体2的button可以得到一个值,现在想做到单击button时将取到的值赋给窗体1的textbox中,同时关闭窗体2
定义事件 窗体2 public delegate void SampleEventDelegate(string s); public event SampleEventDelegate SampleEvent; private void button1_Click(object sender, EventArgs e) { if (SampleEvent != null) { SampleEvent( "test "); this.Close(); } } 窗体1 private void showtext(string s) { MessageBox.Show(s); } private void button1_Click(object sender, EventArgs e) { Form2 f = new Form2(); f.SampleEvent+= new Form2.SampleEventDelegate(showtext); f.ShowDialog(); }