Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to achieve smooth drawing with C# (like Paint .NET)?

How Paint .NET can draw so fast using C#? Sample: The ellipse perimeter is drawn while the mouse is being dragged without any visible delay. At a simple windows form application in C# If you use the MouseMove event of a Picturebox and draw an ellipse based on the mouse position, there will be a lot of delay and flickering! So, how they do it so smoothly?

like image 722
Pedro77 Avatar asked Dec 28 '22 06:12

Pedro77


2 Answers

I have no special knowledge of the Paint.Net code, but most likely it's using Double Buffering, and probably implemented by hand on a custom drawing surface rather than the simplistic implementation in the pre-packaged controls.

like image 61
Joel Coehoorn Avatar answered Jan 16 '23 13:01

Joel Coehoorn


Paint.NET calls Update() after calling Invalidate() which forces an immediate, synchronous WM_PAINT.

like image 37
Rick Brewster Avatar answered Jan 16 '23 13:01

Rick Brewster