禁用.NET进度动画不断变化的价值是什么时​​候? [英] Disabling .NET progressbar animation when changing value?

查看:343
本文介绍了禁用.NET进度动画不断变化的价值是什么时​​候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有对SO有关的动画和progressbars其他问题,但他们似乎围绕着摆脱绘制在进度条,即顶级动画。行进在它的亮点。

我想要做的就是摆脱当我设置进度条的新值所使用的动画。这个问题我现在是在运行完成后,将进度条继续采取行动,增加了他们的最高的位置的的行动已经完成。

在换句话说,如果我的进度的Value属性设置为50,我要立即前往中途位置(如果最大值为100),而不是慢慢建立起来的进度到该位置象现在这样。

如果确有对SO一个问题,这个已经涉及,只是亲如重复,我会高兴地将其删除,但我找不到任何。

这是我找到一个:禁用的WinForms进度动画,它涉及的是突出显示的动画,而这不是我说的。

下面是一个简单的 LINQPad 演示,展示了问题:

 无效的主要()
{
    使用(VAR FM =新表())
    {
        VAR BT =新按钮
        {
            文本=开始,
            位置=新的点(8,8),
            父= FM,
        };
        VAR PB =新进度
        {
            顶= bt.Top + bt.Height + 8,
            宽度= fm.ClientRectangle.Width  -  16,
            左= 8,
            父= FM
        };

        bt.Click + =(S,E)=>
        {
            bt.Enabled = FALSE;
            线程t =新主题(新的ThreadStart(()=>
            {
                Thread.sleep代码(1000);
                bt.BeginInvoke(新动作(()=> {pb.Value = 50;}));
                Thread.sleep代码(1000);
                bt.BeginInvoke(新动作(()=> {pb.Value = 100;}));
                bt.BeginInvoke(新动作(()=> {bt.Enabled = TRUE;}));
            }));
            t.Start();
        };
        fm.ShowDialog();
    }
}
 

修改1:这是Windows 7中,玻璃的主题,所以是的,我敢肯定,这是特定于7或者也可能是Vista的

下面是一个GIF动画,显示的问题,从上面的项目。你可以看到,只要按钮变为启用,过半已定在1秒钟后,该进度动画达100%,的的按钮已被启用。

正如你可以在上面看到,设置按钮,返回到启用和进度设置为100做的同时。基本上,我不想进度的逐步积累,我希望它直接跳转到50%再到100%,同时作为按钮变为启用。


编辑2:在回答大卫·赫弗南的答案,这是我改变了上面的code:

  bt.BeginInvoke(新动作(()=> {pb.Value = 51; pb.Value = 50;}));
Thread.sleep代码(1000);
bt.BeginInvoke(新动作(()=> {pb.Maximum = 101; pb.Value = 101;
                                  pb.Maximum = 100; pb.Value = 100; }));
 

解决方案

这动画的功能的引入在Vista中的Aero主题。

有一个解决办法,但。如果向后移动的进展,将动画中未示出。所以,如果你想让它由51 50提前瞬间,增加值,然后立即用1递减。

您进入冲突时接近100%,因为你不能将值设置为101(我假设最大设置为100)。相反,设置最大为1000,也就是说,增加至1000年,下降到999,然后再搬回到1000。

不管怎么说,这是很怪,但它确实有给你想要的效果的利益!

I realize there are other questions on SO regarding animations and progressbars, but they seem to revolve around getting rid of the animation drawn on top of the progress bar, ie. the highlight that travels over it.

What I want to do is to get rid of the animation that is used when I set the new value of the progress bar. The problem I have now is that the action that is running completes and then the progress bar continues to increase up to their max position after the action has completed.

In other words, if I set the Value property of the progressbar to 50, I want it to travel to the halfway position (if max is 100) immediately, not slowly build up the progressbar to that position as it does now.

If there is indeed a question on SO that already deals with this, just close as duplicate and I'll happily delete it, but I could not find any.

This is the one I found: Disabling WinForms ProgressBar animation, and it deals with the highlight that is animated, and that's not what I'm talking about.

Here's a simple LINQPad demo that shows the problem:

void Main()
{
    using (var fm = new Form())
    {
        var bt = new Button
        {
            Text = "Start",
            Location = new Point(8, 8),
            Parent = fm,
        };
        var pb = new ProgressBar
        {
            Top = bt.Top + bt.Height + 8,
            Width = fm.ClientRectangle.Width - 16,
            Left = 8,
            Parent = fm
        };

        bt.Click += (s, e) =>
        {
            bt.Enabled = false;
            Thread t = new Thread(new ThreadStart(() =>
            {
                Thread.Sleep(1000);
                bt.BeginInvoke(new Action(() => { pb.Value = 50; }));
                Thread.Sleep(1000);
                bt.BeginInvoke(new Action(() => { pb.Value = 100; }));
                bt.BeginInvoke(new Action(() => { bt.Enabled = true; }));
            }));
            t.Start();
        };
        fm.ShowDialog();
    }
}

Edit 1: This is Windows 7, Glass theme, so yes, I bet this is specific to 7 or possibly also Vista.

Here's a GIF-animation that shows the problem, the project from above. You can see that as soon as the button becomes enabled, 1 second after the halfway mark has been set, the progressbar animates up to 100%, after the button has become enabled.

As you can see above, setting the button back to enabled and setting the progressbar to 100 is done "at the same time". Basically, I don't want the progressive buildup of the progressbar, I want it to jump directly to 50% and then to 100% at the same time as the button becomes enabled.


Edit 2: In response to David Heffernan's answer, this is how I changed the above code:

bt.BeginInvoke(new Action(() => { pb.Value = 51; pb.Value = 50; }));
Thread.Sleep(1000);
bt.BeginInvoke(new Action(() => { pb.Maximum = 101; pb.Value = 101;
                                  pb.Maximum = 100; pb.Value = 100; }));

解决方案

This animation feature was introduced in Vista with the Aero theme.

There is a workaround though. If you move the progress backwards, the animation is not shown. So if you want it to advance by 50 instantly, increment Value by 51, then immediately decrement by 1.

You get into strife when close to 100% because you can't set Value to 101 (I'm assuming Maximum is set to 100). Instead set Maximum to 1000, say, increase to 1000, decrease to 999, and then move back to 1000.

Anyway, it's kind of weird, but it does have the benefit of giving you the desired effect!

这篇关于禁用.NET进度动画不断变化的价值是什么时​​候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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