我正在尝试将百分比值放入我的进度条,但它看起来像眨眼然后消失。
这是我的ProgressChanged
活动:
C# 代码
public void button1_click(object sender, EventArgs e)
{
BackgroundWorker _worker = new BackgroundWorker();
_worker.WorkerReportsProgress = true;
_worker.ProgressChanged += new ProgressChangedEventHandler(_worker_ProgressChanged);
_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_worker_RunWorkerCompleted);
_worker.DoWork += (s, e2) =>
{
for (int i = 0; i <= xmlnode.Count - 1; i++)
{
_worker.ReportProgress((int)100 * i / (xmlnode.Count - 1));
// Many validations here
}
}
}
void _worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
// Here I tryied to put the percentage value in progress bar
int percent = (int)(((double)progressBar1.Value / (double)progressBar1.Maximum) * 100);
progressBar1.CreateGraphics().DrawString(percent.ToString() + "%", new Font("Arial", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(progressBar1.Width / 2 - 10, progressBar1.Height / 2 - 7));
}