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

查看:35
本文介绍了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天全站免登陆