사용자 정의 컨트롤을 만들고 있지만 OnPaint()
을 무시하면 계속 호출되지 않습니다.
이 내 코드입니다 :C# 지연없이 계속 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()
을 지연없이 계속 호출 할 수 있습니까?
글쎄 그 창에서 그 코드의 아무 곳이나 다시 칠하지 않아도됩니다. 아마도'this.Invalidate()'또는'this.Refresh()'와 같은'timer_Tick()'내부에서 뭔가를해야 할 것입니다 ... –
이 작품! 많이 고맙습니다!^_ ^ – Ben