I suspect you could do it with reflection by scanning for delegates attached
to each control's events, recording them, removing them, and then adding
them back again later. But do you really need to do that? For most
applications that's like shooting a squirrel with a shotgun. Might even be
considered bad design. I'm 90% sure you can get away with something simpler:
1. Load values into the controls before they're added to the form.
2. Declare a boolean variable IgnoreEvents and check it in all relevant
event-handling code.
3. Manually add and remove event handlers with AddHandler and RemoveHandler.
The first is ideal because it's the simplest but it's not always feasible. I
would lean towards #2 because it makes your code more explicitly stateful:
while debugging, the flow of execution to always hit the handler, you'll
always be able to tell when an event was fired, without having check if the
handler's been removed. What if something goes wrong and the handler isn't
put back? That's a bit harder to track down than just seeing that a variable
'IgnoreEvents' is still set to True. Make IgnoreEvents a Property and you'll
also be able to break on when it's set to a new value.
Bob
"Scott Emick" <se****@ham.fox-international.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How can I disable events for the controls on a form? I tried setting the
form's enable property to false, but that doesn't stop events from firing
on its controls.
I need to temporarily disable a form and load values into controls without
any events firing, then re-enable the form.
--
Scott Emick
Web Programmer
Fox International
Remove the ham from mail address if it's not spam