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?
Asked
Active
Viewed 1,977 times
4
-
Great question - probably doesn't belong on S.O., but still a great question. – Nick Vaccaro Feb 07 '12 at 17:38
-
http://blogs.msdn.com/b/directx/archive/2009/08/14/paint-net-uses-directwrite.aspx – ken2k Feb 07 '12 at 17:40
-
1Here is the link to an answer that has tips from the author of Paint.NET https://stackoverflow.com/a/11025428/11425141 – Phillip Sep 23 '19 at 22:59
4 Answers
4
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.

Joel Coehoorn
- 399,467
- 113
- 570
- 794
-
Thanks. I will search for some DB sample to see if it really improves the drawing. – Pedro77 Feb 07 '12 at 18:56
4
Paint.NET calls Update() after calling Invalidate() which forces an immediate, synchronous WM_PAINT.

Rick Brewster
- 3,374
- 1
- 17
- 21
-
To elaborate on the lower-level details: `Invalidate()` in WinForms calls into the native `InvalidateRect()` function. `Update()` calls the native `UpdateWindow()`. `Refresh()` is the same as calling `Invalidate(true)` followed by `Update()`. – Rick Brewster Dec 15 '15 at 19:25
2
To get smooth drawing you should:
- Use Double Buffering (http://msdn.microsoft.com/en-us/library/b367a457.aspx)
- Use a dedicated toolkit for rendering (OpenGL/DirectDraw etc)
The best way to go in this case is with Double Buffering - it's supported 'out of the box' in the .NET framework, requires very little work, and will eliminate flickering.

Dave Kerr
- 5,117
- 2
- 29
- 31
-
I think double buffering wont fix the delay problem that is more cleary noted when the mouse is moved faster and a gap start to appear betwen its position and the ellipse being drawn. – Pedro77 Feb 07 '12 at 18:53