For forms, a
Form's
"focus" is actually it's activation; you can use
Form.Activate
. If this is some Windows which is not a form, you can use the Answer by Albin. To know if a Window is in foreground you should use Windows API
GetForegroundWindow
which returns
HWND
and compare with
HWND
of the Window in question. You need to use P/Invoke as well as for
SetForegroundWindow
.
This along will not solve your problem. For full resolution, please see these two Answers:
Application focus getting and losing[
^]
Programming on BACKSPACE button[
^]
—SA