【问题标题】:Splash Screen Example启动画面示例
【发布时间】:2011-01-28 04:21:33
【问题描述】:

我只想要一个简单的启动画面示例。

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

但是我能用谷歌搜索的东西太复杂了,太多了。我只想要一个带有越来越透明的图片的表单,直到它自动隐藏并显示我的窗口。

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

Lang 是 c#.net 2.0

【问题讨论】:

标签: c#


【解决方案1】:

创建启动画面可以像您制作/想要的那样简单或复杂。

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

显然,启动画面本身是您必须决定您希望它的外观的东西......

【讨论】:

    【解决方案2】:

    为了让您的初始屏幕成为区域初始屏幕,除了显示正在执行的操作(例如加载客户端)或通过 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() 您的启动屏幕表单。

    稍后我将添加更多细节。现在得走了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-07
      • 2014-01-22
      相关资源
      最近更新 更多