如何在C#中使用刷新进度条 [英] How to use refresh progress bar in C#

查看:138
本文介绍了如何在C#中使用刷新进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用进度条但是虽然我使用刷新功能但它并不令人耳目一新。





I am using a progress bar but it not refreshing though I use refresh function.


if (progressBar.Value == 100)
     {
        progressBar.Value = 0;
        lblProgressPercentage.Text = string.Empty;
     }










 if (ofd.ShowDialog() != DialogResult.Cancel)
    {
        int singleBlock = 100 / ofd.FileNames.Count();

        for (int i = 0; i < ofd.FileNames.Count(); i++)
        {
            ----------------------
                Statements
            ----------------------
        }
progressBar.Value += singleBlock;
                    lblProgressPercentage.Text = progressBar.Value.ToString() + "% Processed";

                    int percent = (int)(((double)progressBar.Value / (double)progressBar.Maximum) * 100);
                    progressBar.CreateGraphics().DrawString(percent.ToString() + "%", new Font("Arial", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(progressBar.Width / 2 - 10, progressBar.Height / 2 - 7));
                    progressBar.Refresh();
                    System.Threading.Thread.Sleep(2000);
}







每当这样做时,进度条不会填充到相应的值。 />


只有在声明退出时才有效。

甚至标签也没有更新。





如何解决此问题。




Whenever do this the progress bar not filling to corresponding value.

It works only if the statement exits.
Even label is not get updated.


How to solve this.

推荐答案

您可以尝试使用这种方法 [ ^ ]。



一个实际例子这里 [ ^ ]。



希望它有所帮助。
You can try with this approach[^].

A practical example here[^].

Hope it helps.


这篇关于如何在C#中使用刷新进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆