现在的位置: 首页 > 综合 > 正文

关闭一个窗体时给另一个窗体中的控件赋值

2011年06月02日 ⁄ 综合 ⁄ 共 472字 ⁄ 字号 评论关闭
现在有两个窗体,窗体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(); }

  

抱歉!评论已关闭.