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



Question:

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


Solution:1

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.


Solution:2

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


Solution:3

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
Previous
Next Post »