Form level focus monitor

S

Steve

I would like to write a routine that will monitor every focus change on the
form and report the name of the control that got focus. I know I could put
code in the gotfocus event of every control and call a central routine, but
is there a way to monitor gotfocus events from one central form level
procedure?

Thanks,

-Steve
 
M

Mythran

Steve said:
I would like to write a routine that will monitor every focus change on the
form and report the name of the control that got focus. I know I could put
code in the gotfocus event of every control and call a central routine, but
is there a way to monitor gotfocus events from one central form level
procedure?

Thanks,

-Steve

Not that I'm aware of. What you can do, though, is something similar to
your gotfocus event handler. Create a procedure with the same signature as
your gotfocus event. In your form load event, loop through all controls on
the form (that you want to log when they get the focus) and attach the got
focus event to the procedure you created above. Have this procedure
monitor/log your focus.

HTH,
Mythran
 
S

Steve

Mythran said:
Not that I'm aware of. What you can do, though, is something similar to
your gotfocus event handler. Create a procedure with the same signature
as your gotfocus event. In your form load event, loop through all
controls on the form (that you want to log when they get the focus) and
attach the got focus event to the procedure you created above. Have this
procedure monitor/log your focus.

HTH,
Mythran
Thanks Mythran,

Sounds like a good idea. Problem is that I'm not sure how to attach the got
focus event to the procedure.
Could I impose on you for some sample code or a hint at where to look in
MSDN?

Thanks again,

Steve
 
M

Mythran

Steve said:
Thanks Mythran,

Sounds like a good idea. Problem is that I'm not sure how to attach the
got focus event to the procedure.
Could I impose on you for some sample code or a hint at where to look in
MSDN?

Thanks again,

Steve

Sure, try AddHandler and RemoveHandler :) Look those up in MSDN..

HTH,
Mythran
 

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