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?
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. Put following line of code at you want.
textBox1.TextChanged -= textBox1_TextChanged;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.