0

My program is a testing. When giving a correct answer, my Progress Bar is increased, but I want to show a percentage of correct answers. I use next code, that I found in the net:

progressBar1.PerformStep();

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));

I place this code in the answer_but_click event. answer_but is a button that checks your answer, define whether it is true or false and counts a general number of given correct answers. Percentage appears for a milisecond and thet disappers. What's the problem?

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
user3560681
  • 101
  • 2
  • 7
  • it's not duplicate. I use the same code as in the question that you give. My problem is that the text with percentage only blinks for miliseconds and disappears. – user3560681 May 05 '14 at 15:19
  • 2
    Sure it's a duplicate. You simply ignored the highest reputation answer posted. You should never use CreateGraphics since it's just a temporary drawing. – LarsTech May 05 '14 at 15:23

0 Answers0