Windows 7 Aero主题进度栏错误? [英] Windows 7 Aero Theme Progress Bar Bug?

查看:116
本文介绍了Windows 7 Aero主题进度栏错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了我认为是Windows 7上的进度条的错误。为了演示该错误,我创建了一个带有按钮和进度条的WinForm应用程序。在按钮的单击句柄中,我有以下代码。

I have ran into what I consider to be a progress bar bug on Windows 7. To demonstrate the bug I created a WinForm application with a button and a progress bar. In the button's 'on-click' handle I have the following code.

private void buttonGo_Click(object sender, EventArgs e)
{
  this.progressBar.Minimum = 0;
  this.progressBar.Maximum = 100;

  this.buttonGo.Text = "Busy";
  this.buttonGo.Update();

  for (int i = 0; i <= 100; ++i)
  {
    this.progressBar.Value = i;
    this.Update();

    System.Threading.Thread.Sleep(10);
  }

  this.buttonGo.Text = "Ready";
}

预期的行为是进度条前进到100%,然后按钮文字更改为就绪。但是,在Windows 7上开发此代码时,我注意到进度条将上升到大约75%,然后按钮文本将变为就绪。假设代码是同步的,就不会发生这种情况!

The expected behavior is for the progress bar to advance to 100% and then the button text to change to 'Ready'. However, when developing this code on Windows 7, I noticed that the progress bar would rise to about 75% and then the button text would change to 'Ready'. Assuming the code is synchronous, this should not happen!

在进一步的测试中,我发现在Windows Server 2003上运行的完全相同的代码产生了预期的结果。此外,在Windows 7上选择非航空主题会产生预期的结果。

On further testing I found that the exact same code running on Windows Server 2003 produced the expected results. Furthermore, choosing a non aero theme on Windows 7 produces the expected results.

在我看来,这似乎是一个错误。当长时间的操作涉及复杂的代码时,通常很难使进度条准确,但是在我的特殊情况下,进度条非常简单明了,因此当我发现进度控制不能准确表示进度时,我几乎不会感到失望。

In my mind, this seems like a bug. Often it is very hard to make a progress bar accurate when the long operation involves complex code but in my particular case it was very straight forward and so I was little disappointed when I found the progress control did not accurately represent the progress.

还有其他人注意到这种行为吗?有人找到了解决方法吗?

Has anybody else noticed this behavior? Has anybody found a workaround?

推荐答案

它与进度条的动画有关。如果进度条为0%,并且将其设置为100%,则它不会跳到那里,而是为进度条动画化。如果太慢,您将在进度栏完成动画制作之前完成操作。因此,即使您已经将其设置为80%,90%和100%,动画仍然落后。

It has to do with the animation of the progress bar. If your progress bar is at 0% and you set it to 100% then it will not jump there, but animate the progress bar smoothly filling up. If this is too slow, you will be done before the progress bar finished animating. So even though you have already set it to 80, 90 and 100%, the animation still lags behind.

我从没找到关闭此功能的方法,但是我有解决方法。仅当您增加进度条时,动画才完成。如果向后移动,它将立即跳到该位置。因此,如果我希望进度条位于x%(x!= 100),则将其移至x + 1,然后移至x。如果我想以100%的价格将其移动到100%,99%和100%。 (或者使用任何值,您都会明白。)这足够快以至于不可见,您也可以将此代码保留在以前的Windows版本中(尽管我不知道)。

I never found a way to turn this off, however I have a workaround. The animation is only being done if you increment the progress bar. If you move it backwards, it will immediately jump to that position. So if I want the progress bar to be at x% (x != 100) then I move it to x+1 and then to x. If I want it at 100% I move it to 100, 99 and 100%. (Or whatever values you use, you get the idea.) This works fast enough to not to be visible, and you can leave this code in for previous Windows versions as well (though I don't).

这篇关于Windows 7 Aero主题进度栏错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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