The following example creates a
Graphics object and sets its clipping region to a rectangle. The code fills two ellipses that intersect the rectangular clipping region. The first ellipse is clipped, but the second ellipse is not clipped because it is filled after a call to
GdipResetClip.
C++
VOID Example_ResetClip(HDC hdc)
{
Graphics graphics(hdc);
// Set the clipping region, and draw its outline.
graphics.SetClip(Rect(100, 50, 200, 120));
Pen blackPen(Color(255, 0, 0, 0), 2.0f);
graphics.DrawRectangle(&blackPen, 100, 50, 200, 120);
// Fill a clipped ellipse in red.
SolidBrush redBrush(Color(255, 255, 0, 0));
graphics.FillEllipse(&redBrush, 80, 40, 100, 70);
// Reset the clipping region.
graphics.ResetClip();
// Fill an unclipped ellipse with blue.
SolidBrush blueBrush(Color(255, 0, 0, 255));
graphics.FillEllipse(&blueBrush, 160, 150, 100, 60);
}
PowerBASIC
SUB GDIP_ResetClip (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pRedBrush AS DWORD
LOCAL pBlueBrush AS DWORD
LOCAL pBlackPen AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Set the clipping region, and draw its outline.
hStatus = GdipSetClipRect(pGraphics, 100, 50, 200, 120, %CombineModeReplace)
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 2, %UnitPixel, pBlackPen)
hStatus = GdipDrawRectangle(pGraphics, pBlackPen, 100, 50, 200, 120)
' // Fill a clipped ellipse in red.
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pRedBrush)
hStatus = GdipFillEllipse(pGraphics, pRedBrush, 80, 40, 100, 70)
' // Reset the clipping region.
hStatus = GdipResetClip(pGraphics)
' // Fill an unclipped ellipse with blue.
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 0, 0, 255), pBlueBrush)
hStatus = GdipFillEllipse(pGraphics, pBlueBrush, 160, 150, 100, 60)
' // Cleanup
IF pBlackPen THEN GdipDeletePen(pBlackPen)
IF pBlueBrush THEN GdipDeleteBrush(pBlueBrush)
IF pRedBrush THEN GdipDeleteBrush(pRedBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipResetClip.png)