大伙说进度条怎么显示!小问题!
private void btnProgressBarStart_Click(object sender, EventArgs e) {
this.labProgressBarShow.Visible = true; //状态显示可见.
this.proBar.Value = 0; //进度条的初始值.
this.proBar.Minimum = 0; //进度条最小值.
this.proBar.Maximum = 10000; //进度条最大值.
this.proBar.Step = 1; //进度条的递增值.
for (int i = 0; i <= this.proBar.Maximum; i += 1) {
this.proBar.PerformStep(); //显示进度条每步的值.
this.labProgressBarShow.Text = "当前进度" + i + ", 总值为 : " + this.proBar.Maximum;
// Thread.Sleep(500); //线程休眠.
}
}
Description:
我让Label显示每步的进度条的 Value,但是不懂为什么都是到结束了才显示:
this.labProgressBarShow.Text = "当前进度" + i + ", 总值为 : " + this.proBar.Maximum;
开始我以为是时间太短了,我设进度条的最大值很大,还是一样不行,甚至我用线程 休眠,干脆就不走了...这怎么解释,解决哈?大侠们!
------解决方案--------------------this.labProgressBarShow.Text = "当前进度" + i + ", 总值为 : " + this.proBar.Maximum;后加上Application.DoEvents();
------解决方案--------------------进度条需要异步啊
------解决方案--------------------进度条值计算放到后台线程,有结果通过委托使前台改变。
------解决方案-------------------- for (int i = 0; i <= this.proBar.Maximum; i += 1) {
this.proBar.PerformStep(); //显示进度条每步的值.
this.labProgressBarShow.Text = "当前进度" + i + ", 总值为 : " + this.proBar.Maximum;
label1.refresh;
// Thread.Sleep(500); //线程休眠.
}
------解决方案--------------------异步+委托,搞定。