开发者

How to close Splashscreen?

I'm writing an application which fetches data from a live engine and works on it. This data is updated every 5 seconds.

Now I'd like to 开发者_JAVA技巧have a splashscreen that shows the progress bar for the first cycle of data fetching. Once the data is fetched for the first time, the application opens the main form showing the data fetched. From hereon the main form fetches data in a loop every 5 seconds.

I've put the code for opening main form in the ProgressChanged event of BackgroundWorker.

private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        progressBar1.Value = Math.Min(e.ProgressPercentage, 100);
        if (progressBar1.Value == 100)
        {                
            SplashScr.ActiveForm.Hide();
            frmMainForm frmMain= new frmMainForm();
            frmMain.WindowState = FormWindowState.Maximized;
            frmMain.Show();

        }
    }

Is there any way of just closing the Splashscreen once Main form has loaded or is this implementation Ok?


I am going to assume that in your Program.Main you have something along these lines:

Application.Run(new SplashForm());

If so it is the reason why your application is closing when you close the splash form. Try something like this:

Application.Run(new MainForm());

Then from the main form you show your splash form and handle it from that end.

HTH


Two possibilities.

I am presuming that your splash screen is your 'main form', which is the first one created by your application. This would then, by default, terminate your application when you close it.

So, either make your splash screen a different form which can be opened and closed at will, keeping your main form open for the GUI, or you need to alter the default operation of the close method - usually this would be to 'minimise on close', but this has the same effect the minimise in your example.


In my opinion , I rather have the splash screen contained within the main form. The splash screen should be shown during the init/load method of the main form , and when the desired % of the data is loaded , it can be closed. So the backgroundworker should be created by the main form itself.

So the progress changed method of the background worker will just close the splash screen. This is fine as the main thread contains the handle

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜