About Threading

I have a winform application which begin with a splash form in a new thread(I used the . When the splash form closes automatically, a login form instanates in the original thread and hold using LoginForm.ShowDialog. However, although a textbox in the Login Form() get the focus, the application become inactive(user cannot type in the textbox immediatlly). User have to click on the form or use Alt-Tab to switch to the Login Form before they can type on the textbox.

How can I make the application keep its focus after the splash form close




Answer this question

About Threading

  • AnaC

    Sorry that my question may be a bit misleading. Let me make it clear. I have two forms, one in each thread. How can I switch focus between the two form

  • Smalldust

    You are using a difficult and ambigious way to do this:

    Try to Create Your SplashForm and put a Timer in that to Close it automatically after X seconds.

    Then in Main Form's Contructor:

    Do this:

    SplashForm splashForm = new SplashForm();

    splashForm.ShowDialog(this); //Will Automatically Closed by the internal Timer

    splashForm.Dispose();

    LoginForm loginForm = new LoginForm();

    if(!loginForm.ShowDialog() == DialogResult.OK) // Not Varified

    {

    Application.Exit();

    }

    loginForm.Dispose();////

    Without Thread you did the same job more clearly and efficiently!

    I hope this will solve your problem and will have proper Focus toooo!

    Best Regards and Best of Luck!



  • UniqueDisplayName-Adam

    Kennon2005 wrote:
    Thanks for your reply. I am actually doing this task exactly the way as you suggest. However, if I do this, there is a flash of the Main Form even the login is unsuccessful. Moreover, it is more "Clean" to put steps in Main() then on the constructor of MainForm before the mainform is shown.

    Right! Do it in Main, and put Application.Run(new Form1()); in the else statement, so that it may execute only when the validation is suceeded!

    Note: Try to elaborate your problem with Code posting!

    I hope this will work!

    Best Regards,



  • samfan

    try maybe doing:

    this.Focus();

    this.Activate();

    after the:

    LoginForm.ShowDialog();

    in your main form - does this help



  • rndy stllwgn

    Kennon2005 wrote:
    Sorry that my question may be a bit misleading. Let me make it clear. I have two forms, one in each thread. How can I switch focus between the two form

    You have reference to both forms in a single class from where they ran Then Call activate Methods on them checking InvokeRequired property!

    What problem are you facing in this

    Best regards,



  • n1c-

    Thanks for your reply. I am actually doing this task exactly the way as you suggest. However, if I do this, there is a flash of the Main Form even the login is unsuccessful. Moreover, it is more "Clean" to put steps in Main() then on the constructor of MainForm before the mainform is shown.

  • About Threading