在 textchanged 上禁用 c# 中的事件处理程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10633661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
disable event handler in c# on textchanged
提问by user123_456
I want to be able to disable or enable textchanged event when I need to. I have made my function, but I need to dismiss event handler, how can I do that?
我希望能够在需要时禁用或启用 textchanged 事件。我已经完成了我的功能,但我需要关闭事件处理程序,我该怎么做?
Here is my code:
这是我的代码:
private void textBox1_TextChanged(object sender, EventArgs e)
{
//something
}
采纳答案by hjgraca
This to add the event
这是添加事件
textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged);
this to remove the event
这是删除事件
textBox1.TextChanged -= new TextChangedEventHandler(textBox1_TextChanged);
Or just the method name
或者只是方法名称
This to add the event
这是添加事件
textBox1.TextChanged += textBox1_TextChanged;
this to remove the event
这是删除事件
textBox1.TextChanged -= textBox1_TextChanged;
Hope it helps.
希望能帮助到你。
回答by Sleiman Jneidi
simply un-register the event
只需取消注册事件
yourEvent-= YourFunction
and if you want to register again
如果你想再次注册
yourEvent+= YourFunction
回答by Pongsathon.keng
You can unsubscribe textchange event. Put following line of code at you want.
您可以取消订阅 textchange 事件。将以下代码行放在您想要的位置。
textBox1.TextChanged -= textBox1_TextChanged;

