Form.LostFocus and Form.GotFocus not working right

  • 10 years ago
    I'm making a DX8 game, running almost entirely in modules, and I want the game to pause automatically if it loses focus.
    I tried putting a GameHasFocus boolean in it, setting it to true or false in the Form.GotFocus and Form.LostFocus events on the form, but it's not working right.
    Can anyone help me out here? Is there an API call for checking on form focus?Embarrassed [:$]

  • 10 years ago

    hi momruoy,

    u don't need any API for form focus, u r right in ur way, but just declare ur boolean variable in ur main module then it'll be public for all form and u can use it to true/false in Form.GotFocus/Form.SetFocus events


    Public GameHasFocus as Boolean      'Declare it in main module


  • 10 years ago

    I guess the problem is that the GotFocus and LostFocus events only work within the application.  E.g. if you show another form within your app.  What you're looking for is responding to the whole application losing focus.  Check the following article on the Microsoft site about how to use a timer and an API call to achieve this:



Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only 3 numbers of interest to a computer scientist: 1, 0 and infinity”