I want to write the rate of progress on the progress bar. I've attached a label to on it. But it's no开发者_如何学JAVAt 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;
}
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.
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.
精彩评论