显示一个WinForms闪屏(Splash Screen)
我的应用程序需要一定的时间来启动。我想在应用程序继续加载时显示一个闪屏(就像Visual Studio .NET和Office应用程序那样)。工具箱中没有这样的控件。我该如何实现呢?
A:
本专栏所附带的代码中包含了一个 SplashScreen类: public class SplashScreen
{
public SplashScreen(Bitmap splash);
public void Close();
}
SplashScreen的构造器可以将显示的位图作为参数。Close方法用来关闭闪屏。通常情况下,我们在处理窗体(form)的Load事件的方法中运用SplashScreen(在图1中可以看到形成的闪屏): private void OnLoad(object
sender,EventArgs e)
{
Bitmap splashImage;
splashImage = new
Bitmap("Splash.bmp");
SplashScreen splashScreen;
splashScreen = new
SplashScreen(splashImage);
//Do some lengthy operations, then:
splashScreen.Close();
Activate();
}
在关闭闪屏后,你必须激活窗体,将它放到最显著的位置。
你可以将任何位图作为一个闪屏。你也可