Results 1 to 3 of 3

Thread: [2.0] Odd Focus Issue on Startup

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Question [2.0] Odd Focus Issue on Startup

    My application is experience an odd issue that makes it so it won't take focus when it starts up.

    This is how it's setup:

    My application first checks to see if any preferences have been created for the application. If they have not, it pops up a MessageBox to let the user know and ask where they want to create them. Once that's done, a second thread is created to display a splash screen.

    Then, if the preferences were just created, my application uses a ShowDialog() on a form asking the user a question. When that's done, the second thread exists and the main form is launched form the main thread. This works great.

    If the preferences were already created, that ShowDialog isn't called and eventually the Splash Screen thread exists and the main form is run from the main thread. When this happens, the main form does not have focus.

    So it sounds like the second thread with the splash screen takes focus but when I call the showdialig from the main thread, it brings it back. In the case where it doesn't call the showdialog, it doesn't come back so how can I bring focus back to the main thread?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Odd Focus Issue on Startup

    Without any prior knowledge of your app that all sounds fairly convoluted. It may be that there is a better solution to address the problem rather than the symptom but a hacky way may be as easy as calling this.Activate in the form's Shown event handler.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2.0] Odd Focus Issue on Startup

    this.Activate() doesn't work in the shown event. It just makes the application flash in the task bar.

    It's not convoluted and the code is fairly small. It's two threads:
    Main Thread - Displays a dialog for the EULA and later uses an Application.Run for the main form
    Secondary Thread - Displays Splash Screen during startup
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width