首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

按下button2使button1的click事件失效 ,如何实现?

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

按下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!");                       
         }

热点排行