OnLostFocus ... who has now the focus ?

  • Thread starter Thread starter cae
  • Start date Start date
C

cae

Hi,

since Control.OnLostFocus doesn't supply in the argument the new window
that gained the focus, how can I get this information ?
Thank you

Herve
 
Try the ActiveControl property on your main form
(you can use Form.ActiveForm to get it)

/claes
 
Thanks for your answer.

However, I called Form.ActiveForm and it returns null.
Since I have a form, how is it possible ?

Herve
 
I also tried the following:

protected override void OnLostFocus(System.EventArgs e)
{
base.OnLostFocus(e);
Control c = ((ContainerControl)TopLevelControl).ActiveControl;

but unfortunately ActiveControl still gives me the control that HAD the
focus, not he one that GAINED the focus. Pretty strange.
TopLevelControl worked as expected, contrarily to ActiveForm...
Any ideas ?

Herve
 
Sorry, my mistake. I missed that you needed it in OnLostFocus.
That method is to early since the new window has not yet
received the focus. Can you move your code to OnLeave instead?

Otherwise you'll need to handle the WM_KILLFOCUS message
(that's the message that causes OnLostFocus to be invoked) and
look at its wParam parameter.

/claes
 
Back
Top