如何在 windows 窗体应用程序中构建启动画面? [英] How to build splash screen in windows forms application?

查看:39
本文介绍了如何在 windows 窗体应用程序中构建启动画面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的应用程序启动时显示启动画面几秒钟.有人知道如何实现吗?

I need to show splash screen on my application start for few seconds. Does anybody know how to implement this?

非常感谢您的帮助.

推荐答案

首先,将您的启动画面创建为无边框、不可移动的形式,上面有您的图像,设置为最初显示在屏幕中央,按照您的方式着色想.所有这些都可以在设计器中进行设置;具体来说,您想要:

First, create your splash screen as a borderless, immovable form with your image on it, set to initially display at the center of the screen, colored the way you want. All of this can be set from within the designer; specifically, you want to:

  • 将表单的 ControlBox、MaximizeBox、MinimizeBox 和 ShowIcon 属性设置为False"
  • 将 StartPosition 属性设置为CenterScreen"
  • 将 FormBorderStyle 属性设置为无"
  • 将表单的 MinimumSize 和 MaximumSize 设置为与其初始大小相同.

然后,您需要决定在哪里显示它以及在哪里关闭它.这两个任务需要在程序的主要启动逻辑的相反侧发生.这可能在您的应用程序的 main() 例程中,也可能在您的主应用程序表单的 Load 处理程序中;无论您在何处创建昂贵的大型对象、从硬盘驱动器读取设置,以及在主应用程序屏幕显示之前通常需要花费很长时间在幕后做一些事情.

Then, you need to decide where to show it and where to dismiss it. These two tasks need to occur on opposite sides of the main startup logic of your program. This could be in your application's main() routine, or possibly in your main application form's Load handler; wherever you're creating large expensive objects, reading settings from the hard drive, and generally taking a long time to do stuff behind the scenes before the main application screen displays.

然后,您所要做的就是创建表单的一个实例,Show() 它,并在您进行启动初始化时保留对它的引用.一旦你的主表单加载完毕,关闭()它.

Then, all you have to do is create an instance of your form, Show() it, and keep a reference to it while you do your startup initialization. Once your main form has loaded, Close() it.

如果您的初始屏幕上有动画图像,则窗口也需要双缓冲",并且您需要绝对确保所有初始化逻辑都发生在 GUI 线程之外(这意味着您不能在主窗体的加载处理程序中有你的主要加载逻辑;你必须创建一个 BackgroundWorker 或其他一些线程例程.

If your splash screen will have an animated image on it, the window will need to be "double-buffered" as well, and you will need to be absolutely sure that all initialization logic happens outside the GUI thread (meaning you cannot have your main loading logic in the mainform's Load handler; you'll have to create a BackgroundWorker or some other threaded routine.

这篇关于如何在 windows 窗体应用程序中构建启动画面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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