this.estateoperation = "CHANGE";
if(??){
  this.button0.Click += new System.EventHandler(this.button0_Click);
}
pushestate();
打??的地方该怎么写.或者用有其它什么方法?

解决方案 »

  1.   

    if(??){
      this.button0.Click += new System.EventHandler(this.button0_Click);
    }直接写成
    this.button0.Click += new System.EventHandler(this.button0_Click);
    就可以了
    在这个地方不需要判断什么
      

  2.   

    如果:
    ...
    this.button0.Click += new System.EventHandler(this.button0_Click);
    ...
    this.button0.Click -= new System.EventHandler(this.button0_Click);
    ...function(){
    ...
    this.button0.Click += new System.EventHandler(this.button0_Click);
    ...
    }
    如果function被调用多次, button0_Click()就会被执行多次
      

  3.   

    this.button0.Click += new System.EventHandler(this.button0_Click);
    如果没有定义会编译部通过的。
      

  4.   

    关键在  button0_Click()就会被执行多次
      

  5.   

    你是不想它执行多次啊?那用这个
    if(this.button0.Click == null){
      this.button0.Click += new System.EventHandler(this.button0_Click);
    }
      

  6.   

    if (((Button)sender).Name == "button0")
    {
    this.button0.Click += new System.EventHandler(this.button0_Click);
    }
      

  7.   

    你是不想它执行多次啊?那用这个
    if(this.button0.Click == null){
      this.button0.Click += new System.EventHandler(this.button0_Click);
    }
    -----------------------------------
    会编译时出错吧
      

  8.   

    我找了一个非标准的方法
    Type t = typeof(Control);
    PropertyInfo pi = t.GetProperty("Events", BindingFlags.NonPublic| BindingFlags.Instance);
    EventHandlerList el = (EventHandlerList)pi.GetValue(button1,null);
    FieldInfo fi = t.GetField("EventClick", BindingFlags.NonPublic | BindingFlags.Static);
    Delegate d = el[fi.GetValue(button1)];
    if( d == null ) ...
      

  9.   

    Reeezak(坚持信念) :会报错:    ...\Form1.cs(321): 事件“System.Windows.Forms.Control.Click”只能出现在 += 或 -= 的左边
      

  10.   

    runrunrun(做最好的自己) :看不啊...........
      

  11.   

    我目前的做法:设一状态变量,
    ...
    this.button0.Click += new System.EventHandler(this.button0_Click);
    ...
    this.button0.Click -= new System.EventHandler(this.button0_Click);
    this.clickestate=true;
    ...function(){
    ...
       if(this.clickestate)
        {
           this.button0.Click += new System.EventHandler(this.button0_Click);
           this.clickestate=false;
        }
    ...
    }