C# 如何在windows应用程序的启动屏幕中设置进度指示器的动画

C# 如何在windows应用程序的启动屏幕中设置进度指示器的动画,c#,winforms,C#,Winforms,我已经在我的windows应用程序中创建了一个启动屏幕。我希望在启动屏幕上添加一个循环“环”进度指示器(如Windows8启动屏幕上显示的指示器),直到连接主窗体。program.cs中的代码是: static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); logo f = new log

我已经在我的windows应用程序中创建了一个启动屏幕。我希望在启动屏幕上添加一个循环“环”进度指示器(如Windows8启动屏幕上显示的指示器),直到连接主窗体。program.cs中的代码是:

static void Main()
{
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);


        logo f = new logo();
        f.Shown += new EventHandler((o, e) =>
        {
            System.Threading.Thread t = new System.Threading.Thread(() =>
            {

                System.Threading.Thread.Sleep(4000);
                f.Invoke(new Action(() => { f.Close(); }));

            });

            t.IsBackground = true;
            t.Start();
        });

}
logo
是我想在windows 8启动中添加进度条或铃声进度指示器的启动窗体或启动屏幕。

默认控件集中没有特定的“循环”进度铃声控件,因此我认为您有两个选项:

添加一个标准的水平
ProgressBar
,并将其样式设置为
Marquee
——这将为您提供不确定的“正在发生进度,但我们不确定何时完成”外观:

如果您想要一个环形/圆形进度指示器,那么最好使用动画.gif或类似工具以及
ImageAnimator
控件

有一个很好的例子,可以加载gif并单步浏览该方法文档中MSDN上的帧:

创建控件,如“AnimatedProgress”:

将此控件添加到
徽标
表单:

public Logo()
{
  InitializeComponent();

  var progressSwirl = new AnimatedProgress();
  progressSwirl.Location = new Point(50, 50);

  Controls.Add(progressSwirl);
}
(我发现通过代码添加比使用设计器效果更好,因为我只是在动画进度控件中粗略地引用了图像,而VS设计器无法找到图像。)

您的自行车戒指将出现在您的启动屏幕上

就显示SpalshScreen属性的启动屏幕的“最简单”方式而言:

首先将对Microsoft.VisualBasic.dll的引用添加到项目中,然后将program.cs更新为类似以下内容:

using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;

namespace WindowsFormsApplication1
{
  public class Startup : WindowsFormsApplicationBase
  {
    protected override void OnCreateSplashScreen()
    {
      SplashScreen = new logo();
    }

    protected override void OnCreateMainForm()
    {
      MainForm = new Form1();
    }
  }

  static class Program
  {
    [STAThread]
    static void Main()
    {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);

      new Startup().Run(new string[]{});
    }
  }
}

为了测试这一点,我在我的主窗体的加载事件中添加了一个
Thread.Sleep(5000)
,在这里,我的徽标页面显示了5秒钟的动画进度,然后加载了我的主窗体。

谢谢Zhaph。但是我得到的白色补丁比gif大5倍
public Logo()
{
  InitializeComponent();

  var progressSwirl = new AnimatedProgress();
  progressSwirl.Location = new Point(50, 50);

  Controls.Add(progressSwirl);
}
using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;

namespace WindowsFormsApplication1
{
  public class Startup : WindowsFormsApplicationBase
  {
    protected override void OnCreateSplashScreen()
    {
      SplashScreen = new logo();
    }

    protected override void OnCreateMainForm()
    {
      MainForm = new Form1();
    }
  }

  static class Program
  {
    [STAThread]
    static void Main()
    {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);

      new Startup().Run(new string[]{});
    }
  }
}