Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form_lost_focus trouble 2

Status
Not open for further replies.

steveouthwaite

Programmer
Feb 12, 2003
165
GB
Hi everyone.
I think I am going mad - I have a prog that contains a form containing a calendar control and a button. The user can select a date from this form, and the date is returned to the appropriate control on the mainform. My problem is that the Form_lost_focus event dosen't seem to fire. the idea is that if the user clicks off the form (i.e. back to the main form without selecting a date or clicking on the button) than I want to be able to set a default value and unload it.
The lost_focus event doesn't fire from any of my other forms aswell. Any Ideas?

Cheers
Steve
 
Try placing your code in Form_Deactivate event instead of Form_LostFocus event.
 
Bingo!
Nice one Hypetia, thanks.

Out of interest, does anyone know when the lost_focus event fires for a form?

Steve
 
There is some oddness about the Form_LostFocus event - use the Form_Deactivate() event instead


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I've been using mousemove events in an MDI app to keep the focus on an MDIchild window, it works but you have to cover every underlying control, this way is just sooo simple. I tried the form lost focus event as steveouthwaite and got nowhere, didn't even think of the Form_Deactivate event. So to Hypetia I award a star.
 
Hi john,

I am curious on your Post. Pls explain the difference and the oddness..

Thanks
Sunil
 
LostFocus event of a form only fires when a form loses focus with NO focus capturing* controls lying on it.
Under this condition, it is the form which has got the focus and clicking another form in the application actually causes the form to lose the focus.

On the other hand, if the form contains a focus caturing control like a command button, text box or list box etc, then the form never receives the focus. Instead the keyboard attention is cycled through the focus capturing controls lying on it. Since the form never receives the focus, obviously it never loses the focus and LostFocus event never fires.

So if you have a form with no focus capturing control on it, like shapes, labels, lines and images; the LostFocus event will work as you are expecting it to do.

The Deactivate event is smarter. It always fires at the appropriate time regardless of the type of control lying on the form.
______
* Focus capturing controls means the control which can recieve keyboard focus, like a text box and not like a label.
 
Thanks Hypetia,

The clarification was enlightening..

Sunil
 
Form_Deactivate works great when it comes to moving to a different form within your application. What about moving from the form to another app you have running. I need to capture this event so I can close other forms.

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top