determine which control will get the focus

G

Guest

When handling the Lost_Focus event, is there a way to determine which control
will get the focus before leaving the Lost Focus handler ? and then prevent
the current control to not loose the focus ?
 
G

Guest

Michael said:
When handling the Lost_Focus event, is there a way to determine which control
will get the focus before leaving the Lost Focus handler ? and then prevent
the current control to not loose the focus ?

You may want to instead subscribe to the control's Leave event. According
to MSDN: "CAUTION Do not attempt to set focus from within the LostFocus event
handler. Doing so can cause your application or the operating system to stop
responding."

To ensure your control doesn't lose focus, place the following line in the
Leave event handler:

this.myControl.Focus();

You can detect which control in your form gains focus by checking the form's
ActiveControl property. Note that if the user switches focus to another
form, the control's Leave event will not be raised. In that case, you should
probably handle the form's Deactivate event.
 

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