gpt4 book ai didi

c# - 如何在 C# 中使用进度条?

转载 作者:太空宇宙 更新时间:2023-11-03 21:18:43 25 4
gpt4 key购买 nike

我想使用 ProgressBar 并在 2 秒内将其从 100% 运行到 0%。我已经编写了以下函数,但它似乎无法正常运行。请帮忙!谢谢!

private async void progessbar()
{
for (iValue = 100; iValue >= 0; iValue--)
{
pbTime.Value = iValue;
await Task.Delay(20);
}
}

最佳答案

如果你想流畅地动画你的进度条,你应该使用 Storyboard:

private void AnimateProgressBar()
{
var storyboard = new Storyboard();

var animation = new DoubleAnimation { Duration = TimeSpan.FromSeconds(2), From = 100, To = 0, EnableDependentAnimation = true };

Storyboard.SetTarget(animation, this.ProgressBar);
Storyboard.SetTargetProperty(animation, "Value");

storyboard.Children.Add(animation);

storyboard.Begin();
}

关于c# - 如何在 C# 中使用进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32252664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com