Getting the window/control that lost the focus

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.
 
P

Peter Duniho

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top