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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide form on lost focus

Status
Not open for further replies.

alehawk

Programmer
Jun 18, 2003
332
0
0
AR
Hi!
I got a form with 2 buttons, what I want to do is that if you click on any parto of the screen or app and my form losts the focus I want it to turn to visible=false
I tryes the form_lostfocus() and I put me.visible=false but nothing happens.
Cand that be done?
How?
Tnx!
 
alehawk (if that is your real name ... ;-) )

I wanted to do something similar a while ago, and have found that, like you, I can't do it.

At first blush, this makes no sense, but a little thought reveals why the observed behaviour is logical.

When a control on the form loses the focus, control stil resides in the form itself. However, if the form itself loses focus, it has no idea what is going on, because control has been taken from it. It's a bit like the person you were talking to suddenly leaving the room without finishing the question he or she just asked - you have no idea how to answer the question, because you didn't hear the rest of it. In the same way, a form has no idea that it has lost focus - all it knows is that it is no longer having a conversation via the user interface, so there is nothing to which it can respond.

I know this doesn't solve your problem, but to my knowledge this is the only "answer".

Best regards,



SmallCraig[upsidedown]
----------------------------------------
"Come see where justice and mercy collide
There on His hands and His feet and His side
 
Tnx for your reply, after reading your comments I went to pscode and I found this that shows when the form lost it focus. Personally I wont check the code to see how it works cause I got to finish this project but I will later, I put the link here so you can check it too for your project.
Tnx Man!
 
Just to elaborate a bit further ...

The Form_LostFocus event doesn't fire because any form that contains at least one control capable of receiving focus will never gain focus itself ... hence can't lose focus. The focus is always on one of the controls on the form.

You could do something like

frm.Hide

in the Form_Activate event of the other form (i.e. the one that you click on) where "frm" is the form that you want to disappear. If you also want this to happen when the user clicks outside the application then you will need to get into the mysteries of API calls and callbacks to make your form vanish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top