using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void form2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //这里应该写什么来取消已经登记的事件?
            Form2 f2 = new Form2();
            toolStripButton1.Click+=new EventHandler(f2.fun);
            f2.Show();
        }        private void form3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //这里应该写什么来取消已经登记的事件?
            Form3 f3 = new Form3();
            toolStripButton1.Click+=new EventHandler(f3.fun);
            f3.Show();
        }
       
    }
}我想用form1里的toolstripbutton去执行form2和form3里的事件,问题是怎样才能取消toolstripbutton上已经登记的事件?
求大神指点

解决方案 »

  1.   


    private EventHandler ev1 = new EventHandler(f2.fun);
    private void form2ToolStripMenuItem_Click(object sender, System.EventArgs e)
    {
    toolStripButton1.Click -= ev1;
    toolStripButton1.Click += ev1;
    }
      

  2.   

    http://topic.csdn.net/u/20120326/21/be53df9b-5753-4062-abec-f0f8108f116d.html
      

  3.   

     toolStripButton1.Click-=new EventHandler(f2.fun);
      

  4.   


    说来说去,反射没有什么特别的,也就是一般的函数调用,只是这一组函数有一个类似的功能。
    如果你对哪个函数不清楚,光标移动上去点F1,查MSDN好了。