c# - 进度条未达到 100%

标签 c# .net winforms scrollbar

我正在 Winforms 中使用滚动条执行一些测试。我有以下代码,这似乎是正确的,但我从未看到滚动条完全填满。当滚动条值达到100时,滚动绘制如图所示(大约50%)。

enter image description here

这是我正在使用的示例代码:

    private void animate_scroll(object sender, EventArgs e)
    {
        progressBar1.Minimum = 0;
        progressBar1.Maximum = 100;
        progressBar1.Step = 1;

        ThreadPool.QueueUserWorkItem(new WaitCallback(AnimateScroll));
    }

    private void AnimateScroll(object state)
    {
        while (true)
        {
            mValue = (mValue + 1) % 101;
            this.Invoke((MethodInvoker)delegate()
            {
                progressBar1.Value = mValue;
                System.Diagnostics.Debug.WriteLine(progressBar1.Value);
            });
            System.Threading.Thread.Sleep(10);
        }
    }

    private int mValue = 0;

最佳答案

根据以下David Heffernan's answer ,问题是由 Windows 7 中添加的动画引起的。通过以下技巧可以解决此问题:

                progressBar1.Value = mValue;
                progressBar1.Value = mValue - 1;

关于c# - 进度条未达到 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23476932/

相关文章:

.net - 应该有 "Undefined Operation"或 "Undefined Result"吗?

c# - 仅限英文字符

c# - 如何将同一个项目中的类编译到不同的DLL

c# - MVC 4 WebAPI 对不可为空类型的验证

c# - LINQ 表达式返回 null

c# - .NET 对象创建,什么更快?

c# - 如何从 Visual Studio.NET 或 Visual Studio 2005 中的 native Visual C++ 代码调用托管 DLL

.net - "CLR20r3"代表什么? (它是什么版本的clr)

c# - 打开/关闭显示电源时触发的事件

c# - 从 NumericUpDown 验证事件中检索 "invalid"值