我正在制作自定义用户控件,但是当我覆盖时OnPaint()
,它不会连续调用。
这是我的代码:
[ToolboxData("<{0}:ColoredProgressBar runat=server></{0}:ColoredPorgressBar>")]
public class ColoredProgressBar : ProgressBar
{
public Timer timer;
public ColoredProgressBar()
{
timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.UserPaint, true);
}
public void timer_Tick(object sender , EventArgs e)
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Call methods of the System.Drawing.Graphics object.
e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), ClientRectangle);
Console.WriteLine("???");
}
}
我等了 10 秒,消息“???” 应该不断出现在我的控制台中,错误我只看到 12 条消息出现。我试过Invalidate(true);
虽然消息不断出现,但表格很滞后。
e.Graphics.DrawString
不是很贵的方法吧?
我怎样才能OnPaint()
无延迟地连续通话?