日期:2014-05-18 浏览次数:21411 次
//1.在Form2中定义一个事件: public event EventHandler OnMybuttonClik; //2.在Form2的按钮事件中触发它: private void button1_Click(object sender, EventArgs e) { if (OnMybuttonClik != null) { OnMybuttonClik(sender,e); } } //3.在Form3中定义一个方法: public void Mybutton_Click(object sender, EventArgs e) { string str= this.textBox1.Text; int num = int.Parse(str); ++num; this.textBox1.Text = num.ToString(); } //4.在Form1中这样显示Form2和Form3: private void Form1_Load(object sender, EventArgs e) { Form2 form2 = new Form2(); Form3 form3 = new Form3(); form2.OnMybuttonClik += new EventHandler(form3.Mybutton_Click); form3.Show(); form2.Show(); }
------解决方案--------------------
楼上正解啊,用委托最方便了,接分了