简体   繁体   English

如何在Windows应用程序的初始屏幕中制作进度指示器的动画

[英]How can I animate a progress indicator in a splash screen of a windows application

I have created a splash screen in my windows application. 我在Windows应用程序中创建了一个初始屏幕。 I want a cycling "ring" progress indicator (like the one shown on the Windows 8 boot screen) to be added on splash screen until the main form is connected. 我希望在初始屏幕上添加一个循环的“响铃”进度指示器(如Windows 8启动屏幕上显示的进度指示器),直到连接主窗体为止。 The code in program.cs is: 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 is the start up form or splash screen I want to add progress bar or ring progress indicator to as in windows 8 startup. logo是我要向Windows 8启动中添加进度条或响铃进度指示器的启动表单或启动屏幕。

There isn't a specific "cycle" progress ring control within the default control set, so I'd say you have two options: 默认控件集中没有特定的“周期”进度环控件,因此我想您有两个选择:

Add a standard horizontal ProgressBar , and set its style to Marquee - this will give you the indeterminate "progress is happening but we're not sure when it's going to finish" look: 添加一个标准的水平ProgressBar ,并将其样式设置为Marquee这将给您不确定的“正在发生的进展,但我们不确定何时会完成”外观:

myProgressBar.Style = ProgressBarStyle.Marquee;

If you want a ring/circular progress indicator, then you're better off using an animated .gif or similar and the ImageAnimator control. 如果需要环形/圆形进度指示器,则最好使用动画的.gif或类似动画以及ImageAnimator控件。

There is a good example of loading a gif and stepping through the frames on MSDN on the documentation for the ImageAnimator.Animate method: ImageAnimator.Animate方法的文档上有一个很好的示例,它加载gif并逐步浏览MSDN上的框架:

Create a control, such as "AnimatedProgress": 创建一个控件,例如“ AnimatedProgress”:

public partial class AnimatedProgress : UserControl
{
  //Create a Bitmpap Object.
  Bitmap animatedImage = new Bitmap("circle_progress_animation.gif");
  bool currentlyAnimating = false;

  //This method begins the animation. 
  public void AnimateImage() 
  {
    if (!currentlyAnimating)
    {
      //Begin the animation only once.
      ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged));
      currentlyAnimating = true;
    }
  }

  private void OnFrameChanged(object o, EventArgs e)
  {
    //Force a call to the Paint event handler. 
    this.Invalidate();
  }

  protected override void OnPaint(PaintEventArgs e)
  {
    //Begin the animation.
    AnimateImage();

    //Get the next frame ready for rendering.
    ImageAnimator.UpdateFrames();

    //Draw the next frame in the animation.
    e.Graphics.DrawImage(this.animatedImage, new Point(0, 0));
  }
}

Add this control to your logo form: 将此控件添加到logo表单中:

public Logo()
{
  InitializeComponent();

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

  Controls.Add(progressSwirl);
}

(I found adding it via code worked better than using the designer as I'd just referenced the image fairly crudely in my AnimatedProgress control and the VS designer couldn't find the image.) (我发现通过代码添加它比使用设计器更好,因为我刚刚在AnimatedProgress控件中粗略地引用了该图像,而VS设计器找不到该图像。)

Your cycling ring will then appear on your splash screen. 然后,您的骑行环将出现在初始屏幕上。

In terms of the "simplest" way to show the splash screen props must go to Veldmius for pointing out the SpalshScreen property: 就显示初始屏幕道具的“最简单”方式而言, 必须向Veldmius指出SpalshScreen属性:

Start by adding a reference to Microsoft.VisualBasic.dll to your project, then update your program.cs to something like: 首先在项目中添加对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[]{});
    }
  }
}

To test this, I added a Thread.Sleep(5000) to the loading event of my main form, and there you have it - my logo page displayed with an animated progress for 5 seconds then my main form loaded in. 为了测试这一点,我在主窗体的加载事件中添加了一个Thread.Sleep(5000) ,就可以了-我的徽标页面显示动画进度5秒钟,然后加载主窗体。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Windows手机的启动画面中为图像制作动画? - How to animate image in splash screen for windows phone? 如何在Windows 8的初始屏幕中添加进度环? - How to add a progress ring to the splash screen in Windows 8? 如何在 windows 窗体应用程序中构建启动画面? - How to build splash screen in windows forms application? 如何在不设置定时器等的情况下在Windows窗体应用程序中构建启动画面? - How do I build a splash screen into a Windows Forms application without setting timers etc? 如何使启动画面变为全屏? - How can I make splash screen to full screen? Windows窗体应用程序-启动屏幕标签未更新 - Windows Form Application - Splash screen label not updating 在Windows 10移动应用程序中显示初始页面而不是初始屏幕 - Display a splash page instead of splash screen in windows 10 mobile application 闪屏后黑屏。 如何在我的应用程序启动时显示图像并稍后在某个时间点将其删除? - Black screen after splash screen. How can I display an image when my application launches and remove it later at a certain point? 我的启动画面结束得太早了。 如何在 Android 上手动隐藏启动画面? - My splash screen ends too early. How can I manually hide a splash screen on Android? 如何在启动画面上报告在.Net中将程序集加载到当前AppDomain的进度? - How do I report progress on loading assemblies into the Current AppDomain in .Net on a splash screen?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM