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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:31:58+00:00 2026-05-31T12:31:58+00:00

Im trying to get a usercontrol to act as a progressbar. As far as

  • 0

Im trying to get a usercontrol to act as a progressbar. As far as i am aware, i need to draw a new bar ontop of the old one and increase its size according to the percentage completed. I have the following code, but unfortunately the green bar is at 100% even though i set the percentage property to 0% when the control is initialized. Im assuming i have made a dumb oversight but i cant see it, any help would be appreciated. Thanks.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    namespace CustomPbar
    {
        public partial class Pbar : UserControl
        {
            private int PercentageValue;
            public int Percentage
            {
                get { return PercentageValue;}
                set 
                {   
                    PercentageValue = value;
                    this.Invalidate();
                }
            }


            public Pbar()
            {
                InitializeComponent();

                Percentage = 0;

                    using(GraphicsPath path = new GraphicsPath())
                    {
                    path.StartFigure();

                    // top left arc 
                    path.AddArc(0, 0, (10), (10), 180, 90);
                    //rect, 180, 90);

                    // top right arc 
                    path.AddArc(((this.Width) - (10)), 0, (10), (10), 270, 90);

                    // bottom right arc 
                    path.AddArc(((this.Width) - (10)), ((this.Height) - (10)), (10), (10), 0, 90);

                    // bottom left arc
                    path.AddArc(0, ((this.Height) - (10)), (10), (10), 90, 90);

                    path.CloseFigure();

                    this.Region = new Region(path);

                    this.BackColor = SystemColors.ControlLight;
                    this.BackgroundImage = new Bitmap(@"c:\users\FrazMan\Desktop\pb1.bmp");
                    this.BackgroundImageLayout = ImageLayout.Stretch;
                }
            }


            protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);

                Rectangle rect = new Rectangle(0, 0, ((this.Width)*((Percentage)/100)), this.Height);

                using (GraphicsPath gp = new GraphicsPath())
                {
                    gp.StartFigure();

                    // top left arc 
                    gp.AddArc(0, 0, (10), (10), 180, 90);

                    // top right arc 
                    gp.AddArc(((rect.Width) - (10)), 0, (10), (10), 270, 90);

                    // bottom right arc 
                    gp.AddArc(((rect.Width) - (10)), ((rect.Height) - (10)), (10), (10), 0, 90);

                    // bottom left arc
                    gp.AddArc(0, ((rect.Height) - (10)), (10), (10), 90, 90);

                    gp.CloseFigure();

                    SolidBrush greenBrush = new SolidBrush(Color.Green);

                    e.Graphics.FillPath(greenBrush, gp);

                    greenBrush.Dispose();
                }

                using(Graphics Draw = this.CreateGraphics())
                {
                    Draw.DrawString(Percentage.ToString() + "%", ProgressBar.DefaultFont, Brushes.Black, new PointF((this.Width / 2) - ((Draw.MeasureString(Percentage.ToString() + "%", ProgressBar.DefaultFont)).Width / 2.0F), 
                        (this.Height / 2) - ((Draw.MeasureString(Percentage.ToString() + "%", ProgressBar.DefaultFont)).Height / 2.0F)));
                }

            }


            protected override void OnResize(EventArgs e)
            {
                base.OnResize(e);
                this.Refresh();
            }
        }
    }
  • 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-31T12:31:58+00:00Added an answer on May 31, 2026 at 12:31 pm

    Several places you create a Rectangle, but never use it. I think you want to use the rect width and height instead of this width and height.

    You should also be using e.Graphics instead of this.CreateGraphics() for drawing the percentage string.

    There is a large amount of duplicate code, and I recommend you keep all drawing code in OnPaint and when you want to redraw, call this.Refresh(). It will help a lot with maintenance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a legacy MFC application and a new WPF usercontrol to
I'm trying to get add a link to a DNN usercontrol where when the
I have a very simple UserControl as shown below. I'm trying to get the
I am trying to get a ProgressBar with the progress of a dataset being
I am trying to add controls to a UserControl dynamically (programatically). I get a
I've started a new job this week and am trying to get my head
Trying to get the value of a property on a usercontrol displayed on a
Just trying to get my head round WPF. I have a usercontrol which I'm
I'm trying to implement a drag-drop function to a usercontrol. I've managed to get
I'm trying to get a user control working asynchronously, yet no matter what I

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.