Odd behaviour when attempting to activate a form.

Hello all,

I have a program where the main form is called (shown/activated) via a keystroke combination. When the form pops-up, I've set the focus to a textbox to begin typing right away.

When the keystroke occurs, I have:


And in the Form_Activated event:


Simple right? It works the way I want it to, even after i've compiled and run the EXE, but ONLY if Visual Studio 2008 is running. Once I close my project in VS, with the program still running outside VS, the form is shown, but input focus is not set to the textbox.

Any ideas on why having my projects' source open in VS has anything to do with running the compiled EXE of said program?

I've even tried API calls to SetForegroundWindow and ShowWindow with the same result.


  • seancampbellseancampbell Pennsylvania, USA
    What object on the Form that is popping up is getting the focus set?

    I never use Form.Activate, ever, not quite sure what your intent for using it is. I really don't have enough information about whats going on to give you an answer. It does seem odd that with VS open the program runs fine (even from the EXE) but when it closes it acts differently.

    I wouldn't be surprised if the events load in a different order when VS is open then when it is closed (or not on a computer). When I first got my job, I wrote a program that would crash on some computers and not on others, it had to do with certain events being called on some, and not on others. I never figured out why that happenned, simply fixed the piece that was crashing and moved on.

    If you post more of the code, I might be able to help you out. Describe exactly what you are trying to do with the Form Active. Maybe it will be as simple as writing a Public Sub that can set the focus to the proper input field, and call that when the KeyPress event says to.

    -Sean Campbell
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion