进度是在Windows窗体慢 [英] ProgressBar is slow in Windows Forms

查看:166
本文介绍了进度是在Windows窗体慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Windows Vista和Visual Studio 2010中创建一个.NET 4的Windows窗体应用程序。删除默认的窗体上的进度条,增加code来处理的形式加载事件,并做了 progressBar1.Value = 100;

I'm using Windows Vista and Visual Studio 2010. Create a .Net 4 Windows Forms Application. Drop a progress bar on the default form, add code to handle the form load event and do a progressBar1.Value = 100; there.

开始调试,您会看到一个动画移动的进度条到100半秒左右。

Start debugging and you see an animation moving the progress bar to 100 in about half a second.

我需要在我的项目2个进度条。一个是全球进展,第二个为当前步骤的进展,因此在第二从0到100和母鸡回到0用于下一步骤。现在的问题是,随着进度条正在缓慢进行一些简单的步骤,它从来没有达到100,它看起来很奇怪。

I need 2 progress bars in my project. One is for "global progress" and the second is for "current step progress" so the second goes from 0 to 100 and hen back to 0 for the next step. The problem is that with the progress bar being slow for some of the quick steps it never reaches 100 and it looks weird.

有没有办法摆脱的动画?在WPF这是确定的,但我宁愿留在Windows窗体。

Is there a way to get rid of that animation? In WPF it's OK but I'd rather stay with Windows Forms.

推荐答案

这是多么的Vista / 7的进度条的设计。当您更改进度条的值,酒吧是动画到该值逐步

This is just how the Vista/7 progress bar is designed. When you change the value of the progress bar, the bar is animated to that value progressively.

我知道避免这种问题的唯一方法是更新进度条的时候往回走,具体如下:

The only way I know of avoiding this problem is to go backwards when updating the progress bar, as follows:

progressBar1.Value = n;
if (n>0)
    progressBar1.Value = n-1;

有关更完整的讨论,请参阅<一href="http://stackoverflow.com/questions/5332616/disabling-net-progressbar-animation-when-changing-value">Disabling .NET进度动画时不断变化的价值?

For a more complete discussion see Disabling .NET progressbar animation when changing value?

这篇关于进度是在Windows窗体慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆