How do I put text on ProgressBar?

后端 未结 9 1425
一向
一向 2020-11-28 07:23

I have used ProgressBar Control in my c# desktop application.I have used it in a thread other then the thread in which control has been declared.Its working Fine. Now I am w

9条回答
  •  孤街浪徒
    2020-11-28 07:48

    I have used this simple code, and it works!

    for (int i = 0; i < N * N; i++)
         {
            Thread.Sleep(50);
            progressBar1.BeginInvoke(new Action(() => progressBar1.Value = i));
            progressBar1.CreateGraphics().DrawString(i.ToString() + "%", new Font("Arial",
            (float)10.25, FontStyle.Bold),
            Brushes.Red, new PointF(progressBar1.Width / 2 - 10, progressBar1.Height / 2 - 7));
         }
    

    It just has one simple problem and this is it: when progress bar start to rising, percentage some times hide, and then appear again. I did't write it myself.I found it here: text on progressbar in c#

    I used this code, and it does work.

提交回复
热议问题