Consistently monitoring when a Form gets/loses focus.

P

Phil Jones

I'm wanting to monitor the focused state of a Form.

In working with the GotFocus and LostFocus events of the Form object I
notice that these only fire if the actual Form object has focus. If any of
it's sub-controls have the focus (which is generally the case) the form will
not fire the event.

I'm wondering - is there a consistent (and proper) way to determine when the
parent Form gets/loses focus, irrespective of which of it's sub-controls has
focus. That is - one form is selected, then when another form is selected
the first form fired an event.

Thanks everyone!

===
Phil
(Auckland | Aotearoa)
 
J

Jeffrey Tan[MSFT]

Hi Phil,

Normally, for Form class, we should use Activated and Deactivate events to
trap the focus change notification, this is the standard rule of windows
programming, for detailed rules and guide, please refer to the "Note"
section of below link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwindowsformscontrolclasslostfocustopic.asp

"Note The GotFocus and LostFocus events are low-level focus events that
are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically,
the GotFocus and LostFocus events are only used when updating UICues. The
Enter and Leave events should be used for all controls except the Form
class, which uses the Activated and Deactivate events."----from the MSDN
link above.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
P

Phil Jones

Ah sweet Jeffrey! Activated and Deactivate it is then. I was really hoping
there was something like this so I didn't have to go and roll some dodgy
kind of code myself.

Many thanks - P.
 
J

Jeffrey Tan[MSFT]

Hi Phil,

You are welcome!! I am glad to work with you. Thanks!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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