Switch between two applications

  • Thread starter Thread starter XingZheng
  • Start date Start date
X

XingZheng

Hi

Could you tell me what event will occur when we switch between two
applications in C#. I can't use Deactivated event of Form because this event
will happen when we choose other form in the same application.

Thanks
 
Hi Xing! the replies from the "Gurus" seem to be a bit slow today in this
ng, so I thought Id have a go at your problem.

The deactivated event is indeed raised when switching between apps and
between forms of the same app.
One way I managed to detect the difference is by using
System.Windows.Forms.Form.ActiveForm

You could therefore create a delegate method that EACH forms' deactivate
event subscribes to. If this is not tested when each forms deactivate event
is fired then you will not always know if the application switch has
happened (depending upon which form was active when it happened).

the simple test could be ...
if (System.Windows.Forms.Form.ActiveForm == null)

//then code to handle when app loses focus

else

//then code to handle when switch between forms


Whether there is an easier way to do this I dont know. I did have a look at
the Application class hoping for a LoseFocus event or something similar -but
unfortunately there wasnt one :(

--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
 
Back
Top