2013-03-08 5 views
0

화면을 직사각형으로 나눈 UserControl을 만들었지 만 내 컨트롤은 OnPaintBackground을 실행 중입니다. 실행하는 동안 여러 번 실행하면됩니다. scrren이 많이 깜박이기 때문에 한 번만 실행하면됩니다.OnPaintBackground 실행 여러 번 C#?

public partial class Schedual : UserControl 
{ 
    int days; 

    public int Days 
    { 
     get { return days; } 
     set 
     { 
      days = value; 
      change = true; 
      Invalidate(true); 
     } 
    } 

    int periods; 

    public int Periods 
    { 
     get { return periods; } 
     set 
     { 
      periods = value; 
      change = true; 
      Invalidate(true); 
     } 
    } 

    Brush brush; 

    bool change = false; 

    List<Panel> panels; 

    public Schedual() 
    { 
     InitializeComponent(); 
     this.ResumeLayout(true); 
     this.days = 1; 
     this.periods = 1; 
     brush = Brushes.White; 
     change = false; 
    } 

    protected override void OnPaint(PaintEventArgs e) 
    { 
     //stuff ....... or base.OnPaint(e); 
    } 

    protected override void OnPaintBackground(PaintEventArgs e) 
    { 
     Graphics g = e.Graphics; 
     var h = this.Height/days; 
     var w = this.Width/periods; 
     for (int i = 0; i < days; i++) 
     { 
      for (int j = 0; j <= periods; j++) 
      { 
       g.FillRectangle(brush, j * w, i * h, w, h); 
       if (change) 
       { 
        AddPanel(j * w, i * h, w, h); 
       } 
       g.DrawLine(Pens.Black, 0, i * h, this.Right, i * h); //draw the horizantle lines 
       g.DrawLine(Pens.Black, j * w, 0, this.Bottom, j * w); //draw the verical lines 
      } 
     } 
     change = false; 
    } 

} 

출력은 다시 ......

+0

더블 버퍼링을 사용하십시오. – SLaks

+0

@SLaks 당신이 이것을하는 방법을 지적 할 수 있습니까? –

답변