2011-11-30 3 views
0

나는 새로운 컨트롤을 생성하고의 OnPaint 이벤트를 overided : 내가 모든 제어 제스처를 탄약을 변경하고있을 때Windows.Forms.Control의 OnPaint를 재정 의하여 깜박입니까?

protected override void OnPaint(PaintEventArgs e) 
    { 
     Graphics g = e.Graphics; 
     _ammo = PitControl.Ammo; 
     var AmmoSize = g.MeasureString(_ammo.ToString(), Properties.Settings.Default.AmmoFont).ToSize(); 
     g.DrawString(_ammo.ToString(), Properties.Settings.Default.AmmoFont, Brushes.WhiteSmoke, Ammo.Location.X - 1, Ammo.Location.Y + Ammo.Height/2 - AmmoSize.Height/2 + 1); 
     Rectangle DrawAmmo = new Rectangle(this.Width - Ammo.Height - _margin, Ammo.Location.Y, Ammo.Height, Ammo.Height); 
     for (int i = _ammo; i > 0; i--) 
      if (i % 2 == 0) 
       g.DrawLine(_ammoPen, Ammo.Location.X + Ammo.Width - i - 1, Ammo.Location.Y + 3, Ammo.Location.X + Ammo.Width - i - 1, Ammo.Location.Y + Ammo.Height - 3); 
     g.DrawRectangle(Pens.Orange, Ammo); 
     g.DrawImage(Properties.Resources.ammunition, DrawAmmo.Location.X, DrawAmmo.Location.Y, DrawAmmo.Height, DrawAmmo.Height); 
    } 

enter image description here

문제입니다.

잘 보이지 않습니다.

g.DrawLine(_ammoPen, Ammo.Location.X + Ammo.Width - i - 1, Ammo.Location.Y + 3, Ammo.Location.X + Ammo.Width - i - 1, Ammo.Location.Y + Ammo.Height - 3); 

그냥 disapeare 탄약이 변경되는 경우 : 어쨌든

내가이 라인에 그릴 라인을 만들어?

답변

3

빠르게 확인할 수있는 것이 하나 있습니다.

양식이 아닌 컨트롤의 경우 DoubleBuffered 속성을 true으로 설정하십시오.

깜박임을 제거해야하지만 Windows.Forms는 일반적으로 게임에 사용하기에 좋지 않으므로 기대 이상의 프레임 속도는 필요하지 않습니다.

+0

여전히 깜박임을 받고 있습니다. – Danpe

+0

일부 구성 요소가 아닌 실제 양식에서 설정 했습니까? 구성 요소에는 DoubleBuffered 속성도 있습니다. WinForms로 작업 한 이후로 오랜 시간이 걸렸지 만, 똑같은 문제가 있다는 것을 기억하고 있으며 DoubleBuffered가 구조 성능에 영향을주었습니다 (심지어 드로잉 성능에 상당한 영향을 미쳤지 만). –

+0

예 폼에 설정했는데 작동하지 않았습니다. ,하지만 지금은 또한 구성 요소에 그것을 설정하고 작동합니다! thx :) – Danpe

관련 문제