Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear all, I am using bellow codes to upload files, everything works perfect except drawing progress value in Progress Bar.
void ftp_ProgressChanged(object sender)
 {
    if (InvokeRequired)
    {
       BeginInvoke(new Progress(ftp_ProgressChanged), sender);
       return;
     }
    FileUpload ftp = sender as FileUpload;
    int prgVal = Convert.ToInt32(ftp.Progress);
    lblUpStatus.Text = string.Format("Uploaded [{0}] {1}% {2}",    ftp.fileSize(ftp.UploadedSize), prgVal, ftp.fileSize(ftp.UpSpeed));
    pbar.Value = prgVal;
    pbar.PerformStep();
    pbar.CreateGraphics().DrawString(prgVal.ToString(), new Font(FontFamily.GenericSerif, 12), Brushes.Red, new PointF(5, 2)); //Runs but i can't see Red Color in exact location (start of progress bar)
 }


the last statement runs successfully but i can't see the red color string in progress bar as the location is exact and correct.
I know it draws but I can't see that, any ideas please?
Posted
Comments
Sergey Alexandrovich Kryukov 25-Apr-11 11:32am    
Create graphics! Oh, not again...
--SA

1 solution

Instead of that, try handling the ProgressBar Paint event: if you don't then the change will cause an invalidate, which will paint over your text...

In addition, you are responsible for Disposing every Graphics object you create:
pbar.CreateGraphics().DrawString(prgVal.ToString(), new Font(FontFamily.GenericSerif, 12), Brushes.Red, new PointF(5, 2));
Will cause a problem when it runs out of handles - which will happen a lot sooner than the Garbage collector gets round to disposing them for you!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Apr-11 11:32am    
Again... OK, the answer gets my 5.
--SA
Abdul Rahman Hamidy 26-Apr-11 23:23pm    
thanks for your answer, that is only a sample i shown, but I did not find OnPaint Event of Progress Bar. any ideas please?
Abdul Rahman Hamidy 27-Apr-11 2:41am    
to my answer, I think i have create a custom progressBar and then override onPaint method, thanks for the answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900