I am making a custom user control , but when i override OnPaint()
, it is not call continuously .
This is my code :
[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("???");
}
}
i waited 10 seconds , message "???" should continuously show up in my Console ,
bug i only see 12 message show up . i tried Invalidate(true);
although message show up continuously , the form is very lag .
e.Graphics.DrawString
is not a very expensive method , right ?
How can i call OnPaint()
continuously without lag?