Click here to Skip to main content
15,913,941 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to show loading picture from changing one form to another when the form loading or processing is long...

What I have tried:

public partial class Form : Form1
{
Private void btn1_Click(object sender, EventArgs e)
{
Form2 f2=new Form2();
this.Hide();
f2.show();
}
}
Posted
Updated 31-Mar-16 20:27pm
Comments
Sergey Alexandrovich Kryukov 1-Apr-16 2:35am    
Sorry, what is that supposed to mean? If you want to show a picture, show it where you want to see it. What "show loading" might be?
—SA

1 solution

Hope this will help.


C#
class SplashForm
{
    //Delegate for cross thread call to close
    private delegate void CloseDelegate();

    //The type of form to be displayed as the splash screen.
    private static SplashForm splashForm;

    static public void ShowSplashScreen()
    {
        // Make sure it is only launched once.

        if (splashForm != null)
            return;
        Thread thread = new Thread(new ThreadStart(SplashForm.ShowForm));
        thread.IsBackground = true;
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();           
    }

    static private void ShowForm()
    {
        splashForm = new SplashForm();
        Application.Run(splashForm);
    }

    static public void CloseForm()
    {
        splashForm.Invoke(new CloseDelegate(SplashForm.CloseFormInternal));
    }

    static private void CloseFormInternal()
    {
        splashForm.Close();
    }
...
}


add this class and a loading form in your code.

and change your code to open new form like below.

C#
Private void btn1_Click(object sender, EventArgs e)
{
SplashForm.ShowSplashScreen();
Form2 f2=new Form2();
SplashForm.CloseForm();
this.Hide();
f2.show();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900