المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Text over Progressbar - Question



C# Programming
09-23-2009, 01:50 AM
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 http://www.barakasoft.com/script/Forums/Images/smiley_confused.gifhttp://www.barakasoft.com/script/Forums/Images/smiley_confused.gif Can anyone else make it work, and if so ... what am I doing wrong?



// call the method
SetProgressBarText(progressBar1, null, ProgressBarText********.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
ProgressBarText******** ********,
//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 ******** (Center or Left)
******** == ProgressBarText********.Left ? 5 :
//Left side
progressBar1.Width / 2 - (gr.MeasureString(Text,
//Centered
TextFont).Width / 2.0F),
// Y ******** (This is the same regardless of ********)
progressBar1.Height / 2 - (gr.MeasureString(Text,
TextFont).Height / 2.0F)));
}
}

public enum ProgressBarText********
{
Left,
Centered
}



Many thanks in advance
Kind regards,



The only programmers that are better C# programmers, are those who look like this -> http://www.barakasoft.com/script/Forums/Images/alien.gif


http://www.barakasoft.com/script/Forums/Images/coffee.gif Programm3r
My Blog: ^_^ (http://www.codeproject.com/script/profile/whos_who.asp?msg=1917620&id=2823228#xx1917620xx)