Suspending event handling
-
On a usercontrol, is there an easy way to suspend all event handling on the control and all child controls? I don't want my event handling to keep firing as I set the form up, rather I just want to call a set of calculating/formatting functions just once in Load(), and then have all the events (which call the calculating/formatting functions) start firing. Right now I have an if statement in each event that ties to a boolean that I set when I want events to start working, but it seems like there might be an easier way. Any suggestions?
-
On a usercontrol, is there an easy way to suspend all event handling on the control and all child controls? I don't want my event handling to keep firing as I set the form up, rather I just want to call a set of calculating/formatting functions just once in Load(), and then have all the events (which call the calculating/formatting functions) start firing. Right now I have an if statement in each event that ties to a boolean that I set when I want events to start working, but it seems like there might be an easier way. Any suggestions?
How about using one method to remove the handlers and another to add. Then you're swichting them on and off in just two places. i.e. private void RemoveHandlers() { button1.Click -= new EventHandler(clickHandler); ---- } private void AddHandlers() { button1.Click += new EventHandler(clickHandler); ---- }