Howdy, Stranger!

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

Categories

Odd behaviour when attempting to activate a form.

booyah_27booyah_27 Member Posts: 1

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:

[code]Me.Activate()[/code]

And in the Form_Activated event:

[code]Textbox1.Focus()[/code]


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.

Comments

  • seancampbellseancampbell Pennsylvania, USAMember Posts: 684 ✭✭✭
    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
    firesickle.com
Sign In or Register to comment.