I'm trying to add some text to the Toolbar toolbar , but so far I have not understood it, here is the code I found HERE :
private void pbPrecentage(ToolStripProgressBar pb) { ProgressBar p = new ProgressBar(); int percent = (int)(((double)(pb.Value - pb.Minimum) / (double)(pb.Maximum - pb.Minimum)) * 100); using (Graphics gr = pb.CreateGraphics()) { gr.DrawString(percent.ToString() + "%", SystemFonts.DefaultFont, Brushes.Black, new PointF(pb.Width / 2 - (gr.MeasureString(percent.ToString() + "%", SystemFonts.DefaultFont).Width / 2.0F), pb.Height / 2 - (gr.MeasureString(percent.ToString() + "%", SystemFonts.DefaultFont).Height / 2.0F))); } }
The problem is that there is no CreateGraphics method in the toolbar progress panel. So I was wondering if anyone was able to successfully add text to the progress bar of the tool.
UPDATE
Well, it looks like ToolStripProgressBar has a progress bar property, which in turn has a CreateGraphics method, but now the problem is that the text value is blinking and blinking, how can I fix it? Here is the revised code:
private void pbPrecentage(ToolStripProgressBar pb) { int percent = (int)(((double)(pb.Value - pb.Minimum) / (double)(pb.Maximum - pb.Minimum)) * 100); using (Graphics gr = pb.ProgressBar.CreateGraphics()) { gr.DrawString(percent.ToString() + "%", SystemFonts.DefaultFont, Brushes.Black, new PointF(pb.Width / 2 - (gr.MeasureString(percent.ToString() + "%", SystemFonts.DefaultFont).Width / 2.0F), pb.Height / 2 - (gr.MeasureString(percent.ToString() + "%", SystemFonts.DefaultFont).Height / 2.0F))); } }
source share