Tutorial :How to add %rate to a progress bar?


I want to write the rate of progress on the progress bar. I've attached a label to on it. But it's not effective. Any easy way to do it ?

private static void ReportStatus(int totalBytes, int processedBytes, Aumpel aumpelObj)  {             progressBar1.Value = (int)(((float)processedBytes / (float)totalBytes) * 100);             labelProgressValue.Text = "Processing %" + progressBar1.Value;  }  


Yes, this was popular back in the Windows 3.x days. You don't see this anymore because it is so difficult to make look good on modern Windows versions. The trouble is the way text is rendered, ClearType rendering requires a well defined background color to get the anti-aliasing pixels to work well. That's hard to come by on a progress bar, especially the Vista and Win7 version with the traveling high-light note.

You'd have to make your own Label control. Make it transparent by overriding CreateParams and turning on the WS_EX_TRANSPARENT style. Also override OnPaint to draw the text, you will have to change e.Graphics.TextRenderingHint to turn off anti-aliasing. The result isn't pretty.


labelProgressValue.Text = string.Format("Processing {0:0.0%}", progressBar1.Value);


I would extend the ProgressBar control and override the OnPaint method and draw the percentage directly on the control.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »