使用C#在进度栏中绘制字符串 [英] Draw String in Progress Bar using c#

查看:135
本文介绍了使用C#在进度栏中绘制字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,我正在使用波纹管代码上传文件,除了在进度栏中绘制进度值之外,其他所有东西都可以正常工作.

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?

推荐答案

相反,请尝试处理ProgressBar Paint事件:如果您不知道, t那么更改将导致无效,这将覆盖您的文本...

此外,您还负责处置您创建的每个Graphics对象:
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!


这篇关于使用C#在进度栏中绘制字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆