简体   繁体   English

在textchanged中禁用c#中的事件处理程序

[英]disable event handler in c# on textchanged

I want to be able to disable or enable textchanged event when I need to. 我希望能够在需要时禁用或启用textchanged事件。 I have made my function, but I need to dismiss event handler, how can I do that? 我已经完成了我的功能,但我需要解雇事件处理程序,我该怎么做?

Here is my code: 这是我的代码:

private void textBox1_TextChanged(object sender, EventArgs e)
{
           //something
}

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. 希望能帮助到你。

simply un-register the event 只需取消注册该活动即可

 yourEvent-= YourFunction

and if you want to register again 如果你想再次注册

 yourEvent+= YourFunction

You can unsubscribe textchange event. 您可以取消订阅textchange事件。 Put following line of code at you want. 根据需要添加以下代码行。

textBox1.TextChanged -= textBox1_TextChanged;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM