Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

c# progressbar with number% displayed inside progress bar

Posted on 2011-03-15
7
Medium Priority
?
3,787 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 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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

971 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