Chinaunix首页 | 论坛 | 博客
  • 博客访问: 474338
  • 博文数量: 112
  • 博客积分: 5696
  • 博客等级: 大校
  • 技术积分: 1720
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-17 09:58
文章分类

全部博文(112)

文章存档

2011年(22)

2010年(28)

2009年(21)

2008年(41)

分类:

2008-04-16 15:33:25

2个windows窗体,每个窗体放一个button,在form1中双击按钮,把form2的时间注册一下 ,如下
 
Form2 f2 = new Form2();
f2.simpleEvent += new delegate_test.Form2.eventHandler(f2_simpleEvent);
f2.ShowDialog();
然后让form2窗体现实出来,
 
private void f2_simpleEvent(string s)
{
   this.label1.Text = s;
}
 
接下来,在form2中,再放入一个textbox,为了传值给form1的,也把form2中的按钮双击,如下
 
if(simpleEvent!=null)
{
   simpleEvent(this.textBox1.Text);
}
 
如果在form1中,已经注册上的话,那么在form2的话,就会拿到事件的值,就会去取得form2中文本框里的值,再返回给form1中
如下方法
private void f2_simpleEvent(string s)
  {
   this.label1.Text = s;
  }
 
从而达到我们要在 form2中输入的值,回调给form1
阅读(2544) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~