更好的启动画面方式 [英] Better way of doing Splash Screen

查看:20
本文介绍了更好的启动画面方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻我得到了这个

更新:感谢所有回答.

 private void Form1_Load(object sender, EventArgs e)
    {
        //hide() doesnt help
        Thread init = new Thread(InitApplication);
        init.IsBackground = true;
        init.Start();
    }

InitApplication 至少需要 5 秒以上才能完成并写入所有设置.我希望我的 splashScreen 保持到那个时候.

InitApplication takes at least 5+ seconds to complete and write in all the settings. I want my splashScreen to stay up until then.

添加:

    private readonly SplashScreen _splash;
    public Form1(SplashScreen splashy)
    {
        _splash = splashy;
        InitializeComponent();
    }

我得到了

static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        SplashScreen splashy = new SplashScreen();
        splashy.Show();
        Application.DoEvents();
        Application.Run(new Form1(splashy));
    }

它正在做它应该做的事情,但是,现在我看到了在 splashform 顶部的 form1.我在哪里可以添加隐藏和显示方法,以便在完全加载时只显示启动画面和 form1 弹出窗口.

It is doing what its suppose to do, However, Now I see form1 on top of the splashform. Where can I add the hide and show method so it only the splash screen is shown and form1 popups when its fully loaded.

推荐答案

您可以使用 Async Await、Background worker 或 Thread 来初始化您的应用程序等.这些都是按照易于使用和遵循的一般模式编写的.

You can use Async Await, Background worker or Thread for initializing your app etc. These are written in the sequence of easy to use and the general pattern being followed.

使用普通的windows窗体,那里有你最喜欢的进度条、gif图像等.在表单加载或表单显示事件中启动后台任务,完成后关闭普通表单并加载您的主应用程序表单.

Use a normal windows form and there use progress bar, gif image etc. what you like most there. On the form load or form shown event start the background task and when it finishes, close the normal form and load your main application form.

如果您的 InitApplication 有任何处理 GUI 的调用,您将必须更改该调用并在 GUI 线程上调用所需的操作.

If your InitApplication has any call that deals with GUI, you will have to change that call and Invoke the desired action on GUI thread.

这篇关于更好的启动画面方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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