Restricting the Drawing Surface in GDI+

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

Restricted Drawing Surface

Clipping with Regions

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.

Restricted Drawing Surface

To draw with clipping, create a Graphics object, set its Clip property, and then call the drawing methods of that same Graphics object:

myGraphics.Clip = myRegion;
myGraphics.DrawLine(myPen, 0, 0, 200, 200);
myGraphics.Clip = myRegion
myGraphics.DrawLine(myPen, 0, 0, 200, 200)

See also