日期:2014-05-17  浏览次数:21104 次

按下button2使button1的click事件失效 ,怎么实现??
两个按钮 
 button1:自动处理
 button2:停止自动处理


按下button2后button1的自动处理事件停止(即button1_click事件失效,)

高手们,该如何实现 ?

thank  u~

------解决方案--------------------
private bool m_bAutoStop=false;
private void button2_Click(object sender, EventArgs e)
{
     m_bAutoStop=true;    //自动处理失效标志
}

private void button1_Click(object sender, EventArgs e)
{
   while(...)
   {
     if(m_bAutoStop) //自动处理失效,跳出自动处理事件
        return;

      //自动处理代码
      ...
        
   }
}

------解决方案--------------------
System.Timers.Timer timer = new System.Timers.Timer();这个定义在全局

private void button2_Click(object sender, EventArgs e)
        {
            m_bAutoStop = true;    
            timer.Enabled = false;
        }

------解决方案--------------------
引用:
引用:C# code?1            this.button1.Click -= new System.EventHandler(this.button1_Click);

private bool m_bAutoStop = false;

        private void button1_Click(object ……


    private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
         {
            if(m_bAutoStop) //失效,停止时钟
            {
              (sender as System.Timers.Timer).Stop();
              return;
            }

             MessageBox.Show("hello!");                       
         }