Getting the window/control that lost the focus

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When processing the OnGotFocus event, I need to know the window/control that
lost the focus. Is there a way to determint this?

With MFC, you could use OnSetFocus which passed you the window that lost the
focus. It there something similar with a c# control.
 
When processing the OnGotFocus event, I need to know the window/control
that lost the focus. Is there a way to determint this?

Not sure...nothing explicit is in the GotFocus event args passed in, so it
doesn't look like it.

However, you could override the WndProc for your control, handling the
WM_SETFOCUS message. You get the window handle that lost the focus in
that message (in the wParam), and then can use the Control.FromHandle()
method to get the actual control.

Seems like an odd oversight for the GotFocus event, considering the
underlying window message provides the information you want, *and*
previous Windows API wrappers (eg MFC) provided that information too.

Pete
 
Back
Top