读书人

按下button2使button1的click事件失效

发布时间: 2013-03-27 11:22:42 作者: rapoo

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

读书人网 >C#

热点推荐