Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

GotFocus

I couldn't get GotFocus() to work, so I tried going to the extreme and put the following code on my main form:

Private Sub Form_GotFocus()
 End
End Sub

However, the program never ends regardless of whether I load another form and switch back, or switch to another program.

Any ideas?
0
aerelorn
Asked:
aerelorn
  • 4
  • 2
  • 2
  • +3
1 Solution
 
tureCommented:
aerelorn,

The form doesn't get focus if there are objects on it that can get the focus.

If you have a simple form with nothing at all on it and show that form, the event procedure will run.

Ture Magnusson
Karlstad, Sweden
0
 
Erick37Commented:
From Help
"A form receives the focus only when all visible controls are disabled."

Therefore the form will not get this event as long as there are any controls on the form capable of getting the focus.
0
 
tureCommented:
:o)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Erick37Commented:
You can subclass the form to see when it gets the focus:

"HOWTO: Determine When Your Application Gains or Loses Focus"

http://support.microsoft.com/support/kb/articles/Q186/9/08.ASP
0
 
Erick37Commented:
:^)
0
 
MarineCommented:
One more thing to be pointed out , never use END within your application. END terminates the program without firing TERMINATE EVENT what this means is that the memory doesn't get released cauing memory leack. Always either unload them or find anohter way to release the resources.
0
 
TheEmpireCommented:
Use a picture box and set its size & properties to match your form, then use the gotfocus event as you wish. Also you may want to set its tab index to 0.
0
 
Erick37Commented:
Still, the last control with focus will only receive the GotFocus event.  If there is a textbox with focus on the picturebox, when reactivating the form, Text1_GotFocus is fired.
0
 
tmackCommented:
Couldnt you use the form_activate event to run code when the form is first activated and in a sense have the 'focus'?? Just a thought...

T
0
 
lhquahCommented:
use Form_activate event instead of form_gotfocus to fire the end command
0
 
tmackCommented:
uhhh....is there an echo in here?
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now