Solved

c# progressbar with number% displayed inside progress bar

Posted on 2011-03-15
7
3,025 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
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 250 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35143275
0
 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now