Dave
Dave

Reputation: 7623

Triggering an event whenever a new window is focused?

I am writing an application using C# and WPF. Is there some way that my app can be notified whenever GetActiveWindow changes, or am I stuck with making a thread and monitoring the changes myself?

Upvotes: 2

Views: 330

Answers (1)

Jalal Said
Jalal Said

Reputation: 16162

use Activated event like:

//at window load or at the constructor
this.Activated += OnWindowActivated;

private void OnWindowActivated(object sender, EventArgs e)
{
     //your code here
}

Edit: As you want it to be for any window in the OS. check this similar question.

Upvotes: 1

Related Questions