Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to stop invoking events when focus is on some controls. (Example I don' want to catch KeyPress event if is selected text box).

I hope this is possible.
Posted

Don't add a handler for the event if you don't want it?

If you don't specify a handler, nothing unusual happens...
 
Share this answer
 
Better than stripping events, is to set flags that tell you in each event handler, if the code should run or not. In key press events, you can also reject the event by setting the Handled property on the eventargs.
 
Share this answer
 
You could also unsubscribe the events as well, but I rather use flags as mentioned by Graus.

FYI: If you have subscribed the event, you unsubscribe it like this:
C#
// Subscribe
this.button1.Click += new System.EventHandler(this.button1_Click);

// Unsubscribe
this.button1.Click -= new System.EventHandler(this.button1_Click);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900