Windows窗体中的进度栏​​实现

时间:2015-12-22 00:39:14

标签: c# .net winforms progress-bar

我尝试在Windows窗体中实现进度条,但进度条在完成整个执行后显示结果。

 public Status()
    {
        InitializeComponent();

    }

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        while (ForReporting.FileProcessed <= ForReporting.TotalNumberFiles)
        {
            Thread.Sleep(100);
            int temp=ForReporting.FileProcessed*100;
            temp = temp / ForReporting.TotalNumberFiles;
            backgroundWorker1.ReportProgress(temp);
        }
    }

    private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        progressBar1.Value = e.ProgressPercentage;
    }

    private void Status_Load(object sender, EventArgs e)
    {
        backgroundWorker1.RunWorkerAsync();
    }

0 个答案:

没有答案