.NET event for application will lose and gain focus

Is there an easy way to detect when a .NET application gains or loses focus?

+3
source share
6 answers

The events you are looking for are Form.Activated and Form. Deactivated

+7
source

I was curious how this method would work under various conditions in an MDI application. It turns out that this will not work in all situations.

MDI-, MDI / , MDI , / ( ). , ( ), MDI / ( , / , , ). , , , / MDI, , / , .

, , / MDI, , ( ShowDialog).

+2

:

this.LostFocus

this.GotFocus

In the parent form / window itself

+1
source

For WPF, FocusChanged in the window. Winforms should have a similar event. You can find out using intellisense in Visual Studio.

Activated / deactivated seems to be standard though.

0
source

In winforms he is Activated

0
source

Handle the Control.GotFocus and Control.LostFocus events for the main window.

0
source

Source: https://habr.com/ru/post/1709100/


All Articles