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 8404325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:34:16+00:00 2026-06-09T22:34:16+00:00

This is the code I’m using: private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { progressBar1.Value

  • 0

This is the code I’m using:

private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
            progressBar1.Value = e.ProgressPercentage;
            progressBar1.Refresh();
            int percent = (int)(((double)(progressBar1.Value - progressBar1.Minimum) /
(double)(progressBar1.Maximum - progressBar1.Minimum)) * 100);
            using (Graphics gr = progressBar1.CreateGraphics())
            {
                gr.DrawString(percent.ToString() + "%",
                    SystemFonts.DefaultFont,
                    Brushes.Black,
                    new PointF(progressBar1.Width / 2 - (gr.MeasureString(percent.ToString() + "%",
                        SystemFonts.DefaultFont).Width / 2.0F),
                    progressBar1.Height / 2 - (gr.MeasureString(percent.ToString() + "%",
                        SystemFonts.DefaultFont).Height / 2.0F)));
            }


            listBox1.Items.Add( "Converting File: " + e.UserState.ToString());
            textBox1.Text = e.ProgressPercentage.ToString();
}

While it’s processing and moving to the right the percentages are some blinkings it’s not smooth enough.

And also when its finishing the process in the end the percentages are gone only the green color is left.

  • 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-06-09T22:34:17+00:00Added an answer on June 9, 2026 at 10:34 pm

    I just tried your code and I see your problem, this is a good question. I researched around and found you need to handle the progress bar’s Paint event and draw on e.Graphics.
    Otherwise, your drawing will be overwritten next time the control paints itself.

    In general, you should never draw on CreateGraphics(). The best way is to subclass the progressbar.

    What you need to do first is create a new class like this

    class MyProgressBar : ProgressBar
    {
        public MyProgressBar()
        {
            this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
        }
    
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = this.ClientRectangle;
            Graphics g = e.Graphics;
    
            ProgressBarRenderer.DrawHorizontalBar( g, rect );
            rect.Inflate(-3, -3);
            if ( this.Value > 0 )
            {
                Rectangle clip = new Rectangle( rect.X, rect.Y, ( int )Math.Round( ( ( float )this.Value / this.Maximum ) * rect.Width ), rect.Height );
                ProgressBarRenderer.DrawHorizontalChunks(g, clip);
            }
    
            // assumes this.Maximum == 100
            string text = this.Value.ToString( ) + '%';
    
            using ( Font f = new Font( FontFamily.GenericMonospace, 10 ) )
            {
                SizeF strLen = g.MeasureString( text, f );
                Point location = new Point( ( int )( ( rect.Width / 2 ) - ( strLen.Width / 2 ) ), ( int )( ( rect.Height / 2 ) - ( strLen.Height / 2 ) ) );
                g.DrawString( text, f, Brushes.Black, location ); 
            }
        }
    }
    

    Then goto the InitializeComponent method like below below and update this.progressBar1 = System.Windows.Forms.ProgressBar();
    to this.progressBar1 = new MyProgressBar();

    #region Windows Form Designer generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.textBox1 = new System.Windows.Forms.TextBox();
                this.listBox1 = new System.Windows.Forms.ListBox();
                this.progressBar1 = new MyProgressBar();
    

    This should now work as you wanted. You code will then be reduced to this

    private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
                progressBar1.Value = e.ProgressPercentage;
    
                listBox1.Items.Add( "Converting File: " + e.UserState.ToString());
                textBox1.Text = e.ProgressPercentage.ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code comes from: http://code.activestate.com/recipes/577090-file-encryption-using-stream-cipher/ import sys import random if len(sys.argv) != 4: print
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This code works properly in my localhost. I am using xampp 1.7.3. but when
This code does not compile. public class Diamond { public static void diamondOfAsterisks(String *
This code i put it in the HTML page for check the file value,
This code works (C# 3) double d; if(d == (double)(int)d) ...; Is there a
This code produces a FileNotFoundException, but ultimately runs without issue: void ReadXml() { XmlSerializer
This code: #include Backpack.h #include <sstream> #include <algorithm> int Backpack::getCurrentWeight() { int weight =
This code below allows me to find the word error in all my files
This code is the core of a much larger script that works great in

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.