Clipping involves restricting drawing to a certain region. The following illustration shows the string "Hello" clipped to a heart-shaped region.

Illustration showing parts of the string "Hello" within a red heart

Regions can be constructed from paths, and paths can contain the outlines of strings, so you can use outlined text for clipping. The following illustration shows a set of concentric ellipses clipped to the interior of a string of text.

Illustration showing the string "Hello" filled by a pattern of concentric circles

To draw with clipping, create a Graphics object, call its SetClip method, and then call the drawing methods of that same Graphics object. The following example draws a line that is clipped to a rectangular region.

Region myRegion(Rect(20, 30, 100, 50));
myGraphics.DrawRectangle(&myPen, 20, 30, 100, 50);  
myGraphics.SetClip(&myRegion, CombineModeReplace);
myGraphics.DrawLine(&myPen, 0, 0, 200, 200);

The following illustration shows the rectangular region along with the clipped line.

Illustration showing a rectangle with a diagonal line from top to bottom



Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions