Question

To enhance performance of drawing a multipoint line with user mouse clicks in C#, I need to invalidate a line instead of rectangle. Is there any way to do this?

panel1.Invalidate();
Était-ce utile?

La solution

(Assuming that we are talking about Windows Forms)

The underlying Windows API will never invalidate anything other than a rectangle, so attempting to do this is entirely pointless. (You can set a non-rectangular clip region, but this doesn't really help with drawing speed.)

See the Microsoft article "Rendering a Windows Forms Control" for details, particularly noting the section entitled Geometry of the Drawing Region which states that "The overloaded versions of Invalidate that take a Rectangle or Region as an argument use that argument to generate the ClipRectangle property of PaintEventArgs".

Thus, a rectangle is always used to represent the invalidated region by creating a clip rectangle that encompasses it.

Another important thing to note is that if multiple invalidated regions are added to the Windows message queue before the window is repainted, all unprocessed ones are combined into a single bounding rectangle that encompasses all of them.

This last point is described in the About Messages and Message Queues MSDN article. Note the "Queued Messages" section which states that "multiple WM_PAINT messages for the same window are combined into a single WM_PAINT message, consolidating all invalid parts of the client area into a single area".

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top