Click here to Skip to main content
16,016,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'd like to be able to do some GUI manipulations when some other application goes to the front (by alt-tabbing, clicking in a foreign window, clicking in the task bar, etc). How do I detect that my application has just been navigated away from?

My desired activity at that point involves showing/hiding multiple windows and I don't want to use the OnDeactivate override because if I hide on Deactivate and show on Activate, I get a flicker if the user is moving from one application window to another.

The "Activation" part is fine. I show my subwindows whenever a main window receives an OnActivated.

If there were an Application.OnActivate(...) / OnDeactivate(...) pair, I wouldn't be posting here. I could just listen in on the Application.OnDeactivate() and hide my child windows, and restore their visibility when Application.OnActivate() would get triggered.
Posted

1 solution

Hi,
I haven't thought this through in any detail but can you use a combination of the Deactivate event and the Form.ActiveForm property.

C#
private void AnyForm_Deactivate(object sender, EventArgs e) {
  if (this.ActiveForm == null) {
    // no active forms
  }
}



Alan.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900