The online racing simulator
Lost/GotFocus events in .NET C#
Hi,

I'm probably being an idiot, but I can't get these to work no matter how correct my code seems to be. I have a window form and I need to run a certain action when the form looses and regains focus. At the moment I have this code (which does squat):


<?php 
namespace FFBTest
{
    public 
partial class Form1 Form
    
{
        ...
 
        public 
Form1()
        {
            
InitializeComponent();
            
this.GotFocus += new EventHandler(Form1_GotFocus);
            
            ...
        }
 
        ...
 
        private 
void Form1_GotFocus(object senderEventArgs ea)
        {
            
DInputHandler.DisableAutoCenter();
            
DInputHandler.ResumeAllEffects();
            
MessageBox.Show("Got focus!");
        }
    }
}
?>

and a similar thing for LostFocus. The *Focus events don't seem to be fired because the Form1_*Focus() methods are not executed. Anybody sees what am I doing wrong? I can post more code if there's a possibility of the events to clash with something else...
Project's target framework is .NET 3.5
You probably have controls on the form. The form never gets focus if there are controls on it, as the focus gets automatically passed to the first control in the tab index. Instead you should use the form's Activated and Deactivate events.
Perfect, you're the man. I kinda wonder why Google didn't come up with this solution as it seems pretty obvious... anyway, thanks.

FGED GREDG RDFGDR GSFDG