Pedro77
Pedro77

Reputation: 5294

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?

Upvotes: 4

Views: 2046

Answers (4)

Rick Brewster
Rick Brewster

Reputation: 3494

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

Upvotes: 4

Pedro77
Pedro77

Reputation: 5294

They probably use WPF. It is much much faster than forms.

Upvotes: 0

Dave Kerr
Dave Kerr

Reputation: 5297

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.

Upvotes: 2

Joel Coehoorn
Joel Coehoorn

Reputation: 415735

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.

Upvotes: 4

Related Questions