我写了一个控件。当我在进度条上执行程序文本时闪烁。
public class ProgressBarPercentage : ProgressBar
{
private int percent;//user defined step
public void SetProgressBarText(string text)
{
using (Graphics gr = this.CreateGraphics())
{
this.Refresh();
gr.DrawString(percent.ToString() + " %", SystemFonts.DefaultFont, Brushes.Black,
new PointF(this.Width / 2 - (gr.MeasureString(percent.ToString() + " %", SystemFonts.DefaultFont).Width / 2.0F),
this.Height / 2 - (gr.MeasureString(percent.ToString() + " %", SystemFonts.DefaultFont).Height / 2.0F)));
}
}
public void SetPercent(int percent)
{
this.percent = percent;
if (this.Value < 100)
this.Value = percent;
else
this.Value = 99;
}
}
static void Main
{
ProgressBarWindow.ProgressBarPercentage progress = new ProgressBarWindow.ProgressBarPercentage();
for (int i = 0; i < 100; i++)
{
progress.SetPercent(i);
progress.SetProgressBarText(i.ToString());
}
}
你能说我做错了什么吗?