?
Solved

c# progressbar with number% displayed inside progress bar

Posted on 2011-03-15
7
Medium Priority
?
3,651 Views
Last Modified: 2013-12-17
Hi,

I'd like to display %number inside the progress bar. I don't know how to do it?
Could you advise me on it?

Thanks,
JT
0
Comment
Question by:jtran007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35136839
0
 
LVL 8

Expert Comment

by:jimsweb
ID: 35136876
Using simple calculations you can do that. try this:

int cal_percent = (int)(((double)(myprogressBar.Value - myprogressBar.Minimum) /
(double)(myprogressBar.Maximum - myprogressBar1.Minimum)) * 100);

on the other hand, if you are looking for some kind of tutorials, u can get it from here.
dreamincode.net/forums/topic/62979-add-the-percent-into-a-progress-bar/
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 1000 total points
ID: 35136880
private void SetProgressBarText(ProgressBar Target, Color TextColor, Font TextFont, int percentage)
        {
            string Text = percentage + "%";
            using (Graphics gr = Target.CreateGraphics())
            {
                gr.DrawString(Text, TextFont, new SolidBrush(TextColor),
                    new PointF(Target.Width / 2 - (gr.MeasureString(Text, TextFont).Width / 2.0F),
                        Target.Height / 2 - (gr.MeasureString(Text,
                        TextFont).Height / 2.0F)));
            }
        }


To use

SetProgressBarText(progressBar1, Color.Black, new Font("Courier new", 10, FontStyle.Bold), 10);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35143282
0
 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35143293
0
 

Author Closing Comment

by:jtran007
ID: 35269021
Thanks,
JT
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question