How to update a progress bar so it increases smoothly?

前端 未结 4 1622
野性不改
野性不改 2020-12-14 08:05

I\'m using progress bar of WPF (C#) to describe the process\'s progress.

My algorithm is below:

DoSomethingCode1();
ProgressBar.SetPercent(10); // 10         


        
4条回答
  •  情歌与酒
    2020-12-14 08:53

    try this out.

    private void updateProgressBar(int percent)
        {
            if (ProgressBar.InvokeRequired)
            {
                updateProgressBarCallback cb = new updateProgressBarCallback(updateProgressBar);
                this.Invoke(cb, new object[] { percent });
            }
            else
            {
                ProgressBar.Value = percent;
                ProgressBar.Update();
                ProgressBar.Refresh();
                ProgressBar.Invalidate();
            }
    

提交回复
热议问题