,如果您使用的是塊進度條,你可以如果你使用一個後臺工作更新這樣
int totalSteps = 10;
for (int i= 1; i<= totalSteps; i++)
{
// One chunk of your code
int progress = i * 100/totalSteps;
blocksProgressBar.Value = progress;
}
blocksProgressBar.Value = 0;
的地位,酒吧可以這樣
private void btnService_Click(object sender, EventArgs e)
{
backgroundWorker.RunWorkerAsync();
}
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
int totalSteps = 10;
for (int i = 1; i <= totalSteps; i++)
{
// One chunk of your code
int progress = i * 100/totalSteps;
backgroundWorker.ReportProgress(progress);
}
}
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
blocksProgressBar.Value = e.ProgressPercentage;
}
private void backgroundWorker_Completed(object sender, RunWorkerCompletedEventArgs e)
{
blocksProgressBar.Value = 0;
}
Source更新
這是行不通的,你不知道該服務需要多長時間。將進度條的Style屬性設置爲Marquee。 –