Clipping Rectangle

Our drawing code up until now has been straightforward, but it is not as efficient as it could be. In OnPaint we always redraw the entire client rectangle, whether it is necessary or not. The PaintEventArg argument that is passed to OnPaint and to paint event handlers contains a property ClipRectangle, which indicates the rectangle in which to paint. By paying attention to this clipping rectangle, you can make your painting code more efficient.

There are two ways in which the clipping rectangle can be set. The first is by the system—for example, when part of a window is obscured by another window and then uncovered. The second is by the program through a call to the Invalidate method of the Control class. This method has several ...

Get Application Development Using Visual Basic® and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.