Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6667455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:56:06+00:00 2026-05-26T02:56:06+00:00

I am trying to add some text to a Tool Strip Progress Bar but

  • 0

I am trying to add some text to a Tool Strip Progress Bar but I have thus far been unsucessful, here is some 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 the Tool Strip Progress Bar doesn’t has a CreateGraphics method. So I was wondering if anyone was able to successfully add text to a Tool Strip Progress Bar.

UPDATE

Ok, it seems that the ToolStripProgressBar has a progress bar property which in turn has the CreateGraphics method, but the problem now is that the text value is blinking and flashing, how would I go about fixing this? 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)));
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:56:06+00:00Added an answer on May 26, 2026 at 2:56 am

    You are running into a very common problem concerning Windows Forms, which is based on GDI+. The standard setting for Double-Buffering for the drawing of controls (and user drawing contexts like graphics) is off. So just add some lines of code to your form:

    public Form1()
    {
    //Activate Double Buffering for all kind of drawing within your form
    this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
    }
    

    If you wanna additionally get nicer graphics then you also should use a SmoothingMode for your drawing context:

    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())
        {
            //Switch to Antialiased drawing for better (smoother) graphic results
            gr.SmoothingMode = SmoothingMode.AntiAlias;
            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)));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add some HTML formatted text to Word using Office Interop. My
I'm trying to add some security to my ASP.NET 1.0 MVC app (VB), but
I am trying to retrieve a web page, add some text at the top
I am trying to have some text added to a Div where I can
Just trying to add some text before function's result. onClick=$('#itempriceqty0').clone().appendTo('#itempricewrapper').attr('id', $('#itempricewrapper').children().length-5+1) So I need
I've been trying to add HTML content to a web view, but can't seem
I'm trying to use a Webview to add some text around a graph produced
I'm trying to load a file, add some text and then save the file,
I' trying to add a text of select box and the some text from
I'm trying to add some syntax highlighting to a text editor in PyQt4. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.