Loosing Applicationfocus when using Splashform

Last post 01-23-2008, 7:39 AM by DexterHaven. 0 replies.
Sort Posts: Previous Next
  •  01-23-2008, 7:39 AM 211

    Loosing Applicationfocus when using Splashform

    Hello everybody

    I’m using the SplashForm class, which is part of the Shareware Starterkit.
    I have one problem whith this class, where you might can help me.
    Perhaps the problem is already known.

    When I show the  splashwindow at startup of my application, it happen that after the splashwindow was closed, and the mainwindow of my app is shown, suddenly  another application (e.g. the WindowsExplorer which is running beside) is popped before my appwindow. In this situation, I have 2 active application windows on screen, which I thought is impossible. But at least both Window title bars are drawn as active window.

    You can reproduce this phenomenon with the recent available starterkit, which I have downloaded right before.

    For this, I have slightly modified the source program.cs of the sample app.
    At first I have removed the complete datastore stuff, which cannot work without adaption.

    Second, I have used the possibility that the splashwindow terminates autmatically after a passed timeperiod. Because the splashwindow runs in a separate thread, both splash- and appwindow are shown.

    The main() function looks now like this

    static void Main()
    {
        Application.EnableVisualStyles();

        // Add and event handler to handle unhandled exceptions.
        Application.ThreadException += new System.Threading.ThreadExceptionEventHandler
       
    Application_ThreadException);

        //launch the splash screen on a seperate thread
        //The first value passed in disables the timer that automatically closes the form.
        //The second value passed is the fade constant, which determines the change in
        //form opacity for every interval of the fadeTimer
        //
    The third value is the interval for the fadeTimer in ms

        // terminate the splashwindow automatically after 3 seconds
        int splashTimeout = 3000;
       
    double fadeConstant = 0.05;
        int fadeTimer = 35;
        SplashForm.Showasyncsplash(splashTimeout, fadeConstant, fadeTimer);
       
    SplashForm.StatusText = "Initializing Application ...";

        // wait a second before starting the main form
        System.Threading.Thread.Sleep(1000);

        Application.Run(new Form1());

    }

    Beside this I have used the TopMost property instead of TopLevel for the splashwindow, to ensure that it is always on top of the appwindow.

    With TopLevel it is not always the case, that the splashwindow is always on top. Sometimes yes, sometimes no. But when it was on top, the behaviour was the same. So I used TopMost, to be sure to demonstrate the behaviour.

    And with this change, you should be able to reproduce the described phenomenon.
    Start the sampleapp with a doubleclick on the executable in the windowsexplorer.

    In that moment the splashwindow disappears, the windowsexplorer window is popped in front of the sampleapp window, and both seems to be active.

    Have you an explanation and hopefully also a solution to avoid this, means that my appwindow is fore sure the topmost window after start, what everybody would expect.

    Thanks in advance for your support.

    Regards
    Dexter Haven

View as RSS news feed in XML
Welcome!   Sign in | Join | Help