如何显示从一种形式到另一种形式的加载图片? [英] How to show loading picture from one form to another?

查看:88
本文介绍了如何显示从一种形式到另一种形式的加载图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在表单加载或处理很长时显示加载图片从更改一个表单到另一个表单...



我尝试过:



public partial class Form:Form1

{

Private void btn1_Click(object sender, EventArgs e)

{

Form2 f2 = new Form2();

this.Hide();

f2.show();

}

}

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();
}
}

推荐答案

希望这会有所帮助。





Hope this will help.


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.

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


这篇关于如何显示从一种形式到另一种形式的加载图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆