Solved

c# progressbar with number% displayed inside progress bar

Posted on 2011-03-15
7
2,913 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
LINQ question 7 22
Pass through dll 2 38
ConsoleSql 1 18
Round up to 100% in .NET 10 45
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

22 Experts available now in Live!

Get 1:1 Help Now