How to know if Deactivate Event is caused by closing?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an event handler that is called when Deactivate even is raised. The
reason is I want the form to do some stuff when it is deactivated, e.g., when
screen saver starts to run. However, whenever I close the window, the
deactivate even handler get called also. And it run into errors since some
resources are no longer available when the form is closing.
Is there a way to know that the form is closing so I don't do anything in
Deactivate event handler?

Thanks
 
Hi QL,

Both Closing and Closed events seem to be called before Deactivate when
closing the form. Thus in response to some of them (perhaps Closed) you can
unhook from Deactivate. I'm not sure that the order of the events are
standard. I couldn't find in MSDN documented order of those events. So
chances the order to change in future versions is not 0.
 
Thanks for the advice. I set a flag in closing event and check it in
deactivate handler. Works great.
 
Back
Top