How to know if Deactivate Event is caused by closing?

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
 
S

Stoitcho Goutsev \(100\) [C# MVP]

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.
 
G

Guest

Thanks for the advice. I set a flag in closing event and check it in
deactivate handler. Works great.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top