Fr3shlama
Fr3shlama

Reputation: 33

Preloading a form in WPF c#

I am currently trying to make a Loading form which should stay on screen for 7 seconds before switching to the main form

I cant just simply load the main form directly after the loading bar is full because the Main form takes about 7 seconds to start

Is there i way to "pre load" the main form, but hiding it until the loading form is done?

This is the code for the loading form, simplyfied

      private void FormLoading_Load(object sender, EventArgs e)
    {
        tick.Start();
    }

    private void tick_Tick(object sender, EventArgs e)
    {
        loadingbar.Increment(1);

        if (loadingbar.Value == 700)
        {
            this.Close();
        }
    }

Upvotes: 0

Views: 223

Answers (1)

dsdel
dsdel

Reputation: 1062

I would add a Splashscreen - this way you do not need to use a timer for waiting until the form is loaded. You simply display the splash screen at startup and close it inside the MainWindows Constructor.

You can add a splash screen by Visual Studio -> Right click your project -> Add new item -> Wpf -> Splashscreen.

If you really want that the form does display there for 7 seconds you can use Thread.Sleep before closing the Splashscreen.

Upvotes: 2

Related Questions