저는 ms 페인트와 비슷한 작은 페인팅 프로그램을 만들고 있습니다. 지금은 'select function'을 구현하려고합니다. 나는 약간의 연구를했기 때문에 깜박 거리는 문제에 직면 해있다. 그리고 나는 내 자신의 Panel 클래스를 만들어야한다는 것을 알았다. 그게 - 내가 여기에 점 P1 이중 버퍼링이 패널에서 작동하지 않습니까?
- MouseDown :
MyDisplay panel1 = new MyDisplay(); Graphics graphics1 = panel1.CreateGraphics();
내가 패널에 3 개 이벤트를 사용
public class MyDisplay : Panel { public MyDisplay() { this.DoubleBuffered = true; this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.ContainerControl | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor , true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.UpdateStyles(); } }
주요 양식의 필드가 있습니다 깜박 거리는 문제가있어서
graphics1.drawRectangle(...)
및graphics1.Clear()
클릭 할 때마다 마우스가 움직입니다. - MouseUp - 방금 마지막으로 사각형을 그립니다.
무엇이 잘못 되었나요? 전체 패널이 흰색이고 거기에 1 개의 직사각형 만 있지만 왜 여전히 깜박 거리는 문제가 발생합니까? 고맙습니다.
편집 :
내가 덮어 OnPaint 메서드를했습니다하지만 난 여전히 다음에 무엇을 모른다.
protected override void OnPaint(PaintEventArgs e)
{
// Call the OnPaint method of the base class.
base.OnPaint(e);
// Call methods of the System.Drawing.Graphics object.
e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), ClientRectangle);
}
EDIT2 : 내가 비트 맵/이미지에 페인트 거기에서 이미지를 복사 패널에 붙여 넣기 방법을 OnPaint를 무시 하는가?
CreateGraphics()를 사용하여 이중 버퍼링 된 기능을 파괴하고 있습니다. 페인팅을 수행하고 깜박임을 피하려면 ** OnPaint() 메서드를 재정의해야합니다. –
OnPaint 사용에 대한 팁을 알려주시겠습니까? 나는 아무런 단서가 없다는 것을 어떻게 알았습니까? 결과가없는 google에서 찾으려고 노력했습니다. – Patryk