2014-09-25 88 views
1

我在Windows应用程序中创建了启动画面。我想要在启动画面上添加一个循环“环形”进度指示器(如Windows 8启动画面上显示的进度指示器),直到主窗体连接。 Program.cs中的代码是:如何在Windows应用程序的启动画面中为进度指示器设置动画

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的启动。

回答

2

没有一个特定的“循环”进步圈默认的控制集中控制,所以我说你有两个选择:

添加标准水平ProgressBar,其样式设置为Marquee - 这会给你不确定的“进度发生,但我们不知道它什么时候结束”的样子:

myProgressBar.Style = ProgressBarStyle.Marquee; 

如果你想要一个戒指/圆形进度指示器,那么你最好不要使用动画。 gif或类似的和ImageAnimator控件。

有加载GIF和通过MSDN上的帧为ImageAnimator.Animate方法的文档上踩着一个很好的例子:

创建一个控制,如“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)); 
    } 
} 

添加这种控制你的logo形式:

public Logo() 
{ 
    InitializeComponent(); 

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

    Controls.Add(progressSwirl); 
} 

(我发现通过代码添加它的工作比使用的设计师,因为我”好d只是在我的AnimatedProgress控件中相当粗略地引用了图像,而VS设计人员找不到图像。)

然后,您的循环环将出现在启动屏幕上。

在的“最简单”的方式来显示启动画面props must go to Veldmius您指出的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秒钟,然后我的主要形式加载动画的进步我的标志页

+0

谢谢Zhaph.but我得到比gif大5倍的白色补丁 – amar 2014-09-27 03:22:25

相关问题