this.button1.Click -= new System.EventHandler(this.button1_Click);  
this.button1.Click +=new System.EventHandler(this.testok);

解决方案 »

  1.   

    这样我当然是可行的
      但是如果在下面的语句中
         this.button1.Click -= new System.EventHandler(this.button1_Click);  
      
    如果 this.button1_Click 这个函数名是未知的动态的
    就是说不知道当前要 减去的 到底是 testok 还是 button1_Click 
    或者说 函数名根本不知道 怎么 做到呢?怎样才能得到当前的 EventHandler 呢?
      

  2.   

    too bad, the mechanism of event disallows you to get the list of currently registered delegates through something like Delegate.GetInvocationList(), consider to write some code to keep track of those delegates yourself
      

  3.   

    你原来button1已经有Click  EventHandler了
    需要this.button1.Click -= new System.EventHandler(this.button1_Click);  

      

  4.   

    没办法,只好减去你所知道的了,正如思归大虾所说, keep track of those delegates yourself
      

  5.   

    难道 用一个 hashtable 将每次绑定后的 EventHandler 保存起来?
    在绑定之前减去所有的?
    然后在 做 += ? 
    我觉的这样不大好
    难道真的没有 好的办法?
      

  6.   

    因为event 只能出现在 += 或-= 的左边(如果没有这个限制就好多了:( ),所以你必须用一个集合来维护委托示例代码
    mydelegate +=  new MyDelegate1(Event11);
    testEvent.Event1 += new MyDelegate1(Event11);;foreach(MyDelegate1 d in mydelegate.GetInvocationList())
    {
      MessageBox.Show( d.Method.Name);
    }