启动画面示例

我只想要一个简单的Splash Screen示例。

获取代码,插入我的图片,添加2行代码加载和完成。

但我只能谷歌这么复杂,太多了。 我只想要一张图片越来越透明,直到它自动隐藏并显示我的窗口。

我尝试了Codeproject的“prettygoodsplashscreen”,但不适合我。

Lang是c#.net 2.0

创建启动画面可能与您想要的一样简单或复杂。

private void Form1_Load(object sender, System.EventArgs e) { // Display the splash screen var splashScreen = new SplashForm(); splashScreen.Show() // On the splash screen now go and show loading messages splashScreen.lblStatus.Text = "Loading Clients..."; splashScreen.lblStatus.Refresh(); // Do the specific loading here for the status set above var clientList = _repository.LoadClients(); // Continue doing this above until you're done // Close the splash screen splashScreen.Close() } 

显然,Splash Screen本身就是你必须决定你想要它的样子……

为了使您的启动屏幕成为区域启动屏幕,它不应该有其他代码而不是显示它正在做什么(例如加载客户端)或通过ProgressBar控件显示应用程序启动的进度。

以下是步骤:

  1. 实例化BackgroundWorker,您将在BackgroundWorker.DoWork()方法中启动加载;
  2. 在主Form_Load()事件中,调用BackgroundWorker.RunWorkerAsync()方法;
  3. 在您的Form_Load()事件中,在调用RunWorkerAsync()之后,实例化并向您的用户显示启动画面SplashForm.ShowDialog()
  4. 报告LoadClient()方法中的进度,例如,使用BackgroundWorker.ProgressChanged()事件(您也可以报告BackgroundWorker正在做什么(“加载客户端……”);
  5. 在RunWorkerCompleted()事件中,您可以使用Splash.Close()启动屏幕窗体。

我稍后会补充一些进一步的细节。 要离开了。