views:

371

answers:

1

My app displays a login box on start up, I've been able to make it top most, however it is not set focused until I click on it.

How do you make it so it's automatically focused?

+3  A: 

You could call Activate() explicitly, for example in the log-in dialog's Load event handler.

Alternatively, you could show the dialog modally, by calling the ShowDialog() method rather than Show() — that should cause it to be focused.

I suspect what is happening though is that you are showing the dialog before the owning window has fully activated, and that the main form is stealing back focus. Perhaps you are trying to show the log-in dialog in the main form's constructor or Load event handler? If that is the case, you may be better off modifying your bootstrap loader (Program.cs) to show the log-in dialog before showing the main form.

(As already suggested, post the code if you want a better advice.)

Paul Ruane
go with ShowDialog for a login form.
scottm