Label label = new Label();
label.Dock = DockStyle.Top;
label.Text = "0";
ProgressBar progressBar = new ProgressBar();
progressBar.Dock = DockStyle.Top;
progressBar.Step = 10;
this.Controls.Add(label);
this.Controls.Add(progressBar);
(new Task(() =>
{
for (int i = 1; i <= 10; i++)
{
this.Invoke(new Action(() =>
{
label.Text = i.ToString();
progressBar.PerformStep();
}));
Thread.Sleep(500); // 至少500, 根据Step的不同来调整, 原理就是等待的时间用来渲染进度条的动画效果
}
})).Start();
使用等待来处理延迟动画效果的问题