Click here to Skip to main content
15,941,973 members
Home / Discussions / C#
   

C#

 
QuestionCustom progressbar doesn't update Pin
teknolog12322-Sep-09 1:56
teknolog12322-Sep-09 1:56 
QuestionRe: Custom progressbar doesn't update Pin
Programm3r22-Sep-09 3:21
Programm3r22-Sep-09 3:21 
AnswerRe: Custom progressbar doesn't update Pin
teknolog12322-Sep-09 4:02
teknolog12322-Sep-09 4:02 
GeneralRe: Custom progressbar doesn't update Pin
Programm3r22-Sep-09 21:21
Programm3r22-Sep-09 21:21 
GeneralRe: Custom progressbar doesn't update Pin
teknolog12323-Sep-09 9:26
teknolog12323-Sep-09 9:26 
QuestionBinary Serialization of Dictionary Pin
FJJCENTU22-Sep-09 1:28
FJJCENTU22-Sep-09 1:28 
AnswerRe: Binary Serialization of Dictionary Pin
Henry Minute22-Sep-09 1:44
Henry Minute22-Sep-09 1:44 
QuestionText over Progressbar - Question Pin
Programm3r22-Sep-09 1:25
Programm3r22-Sep-09 1:25 
Hi all,

I found the following code, that allows one to write a string on a ProgressBar ... Only thing is that I can't get it to work Confused | :confused: Confused | :confused: Can anyone else make it work, and if so ... what am I doing wrong?

// call the method
SetProgressBarText(progressBar1, null, ProgressBarTextLocation.Centered, Color.Black, SystemFonts.DefaultFont);

// Set the ProgressBar Text method
private void SetProgressBarText(System.Windows.Forms.ProgressBar Target,
    //The target progress bar
string Text,
    //The text to show in the progress bar
ProgressBarTextLocation Location,
    //Where the text is to be placed
System.Drawing.Color TextColor,
    //The color the text is to be drawn in
System.Drawing.Font TextFont
    //The font we use to draw the text
)
{
    //Make sure we didn't get a null progress bar
    if (Target == null)
        throw new ArgumentException("Null Target");

    //Now we can get to the real code
    //Check to see if we are to add in the percent
    if (string.IsNullOrEmpty(Text))
    {
        //We are to add in the percent meaning we got a null or empty Text
        //We give text a string value representing the percent
        int percent = (int)(((double)(Target.Value - Target.Minimum) / (double)(Target.Maximum - Target.Minimum)) * 100);
        Text = percent.ToString() + "%";
    }
    //Now we can add in the text
    //gr will be the graphics object we use to draw on Target
    using (Graphics gr = Target.CreateGraphics())
    {
        gr.DrawString(Text,
        TextFont,
            //The font we will draw it it (TextFont)
        new SolidBrush(TextColor),
            //The brush we will use to draw it
            //Where we will draw it
        new PointF(
            // X location (Center or Left)
        Location == ProgressBarTextLocation.Left ? 5 :
            //Left side
        progressBar1.Width / 2 - (gr.MeasureString(Text,
            //Centered
        TextFont).Width / 2.0F),
            // Y Location (This is the same regardless of Location)
        progressBar1.Height / 2 - (gr.MeasureString(Text,
        TextFont).Height / 2.0F)));
    }
}

public enum ProgressBarTextLocation
{
    Left,
    Centered
}


Many thanks in advance
Kind regards,


The only programmers that are better C# programmers, are those who look like this -> Green Alien | [Alien]



Java | [Coffee] Programm3r

My Blog: ^_^

AnswerRe: Text over Progressbar - Question Pin
Programm3r22-Sep-09 1:36
Programm3r22-Sep-09 1:36 
AnswerRe: Text over Progressbar - Question Pin
firda-cze18-Apr-10 22:21
firda-cze18-Apr-10 22:21 
GeneralRe: Text over Progressbar - Question Pin
Scott Sherin28-May-10 4:15
Scott Sherin28-May-10 4:15 
Questionhow to use a macro in c# Pin
Ajithevn22-Sep-09 0:58
Ajithevn22-Sep-09 0:58 
AnswerRe: how to use a macro in c# Pin
Programm3r22-Sep-09 1:39
Programm3r22-Sep-09 1:39 
GeneralRe: how to use a macro in c# Pin
Ajithevn22-Sep-09 2:29
Ajithevn22-Sep-09 2:29 
GeneralRe: how to use a macro in c# Pin
Programm3r22-Sep-09 2:50
Programm3r22-Sep-09 2:50 
GeneralRe: how to use a macro in c# Pin
Programm3r22-Sep-09 2:53
Programm3r22-Sep-09 2:53 
GeneralRe: how to use a macro in c# Pin
thecodedemon23-Sep-09 13:30
thecodedemon23-Sep-09 13:30 
AnswerRe: how to use a macro in c# Pin
Programm3r22-Sep-09 2:57
Programm3r22-Sep-09 2:57 
QuestionPlaying with Enumerations Pin
ezazazel22-Sep-09 0:45
ezazazel22-Sep-09 0:45 
AnswerRe: Playing with Enumerations Pin
harold aptroot22-Sep-09 0:54
harold aptroot22-Sep-09 0:54 
AnswerRe: Playing with Enumerations Pin
Gideon Engelberth22-Sep-09 2:51
Gideon Engelberth22-Sep-09 2:51 
GeneralRe: Playing with Enumerations Pin
ezazazel22-Sep-09 6:49
ezazazel22-Sep-09 6:49 
AnswerRe: Playing with Enumerations Pin
PIEBALDconsult22-Sep-09 4:07
mvePIEBALDconsult22-Sep-09 4:07 
GeneralRe: Playing with Enumerations Pin
ezazazel22-Sep-09 6:47
ezazazel22-Sep-09 6:47 
GeneralRe: Playing with Enumerations Pin
PIEBALDconsult22-Sep-09 13:52
mvePIEBALDconsult22-Sep-09 13:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.