Search code examples
c#winformseventsvisual-studio-2015mousehover

Form activation stops work in same compilation exe


I've winfoms window this.Activate(); in Form1_MouseHover event:

private void Form1_MouseHover(object sender, EventArgs e) 
{ 
       this.Activate();
}

I've build project exe from studio, form activation works with MouseHover.

Then I closed VS, and open exe from bin folder, activation works same way.

I did not make any changes and did not recompiled exe, I've opened exe second time, activation works, but somehow slower, I've closed it and open once again, activation just does not works.

First I was think, that's my Visual Studio-15 does not compiles updated code, but seems like it something different, because change in functionality happens with same, not recompiled exe, and also I've added additional code, first of all to check if update exist in compilation, and also to fire particular event. Program was updated, and event exist. With first or several opening of form, activation stops to work, but always works after build from VS


Solution

  • The documentation for Form.Activate says this:

    Activating a form brings it to the front if this is the active application, or it flashes the window caption if this is not the active application.

    I would assume that as you're in VS when you first run it the application is considered the active application but when you run it from explorer it's not the active window.

    I did a quick test, ran it in VS and it worked as you said, switched focus. When I ran it from Explorer it just flashed the taskbar.