The following example creates a
Graphics object and sets its clipping region. The code translates the clipping region 100 units to the right and then fills a large rectangle that is clipped by the translated region.
C++
VOID Example_TranslateClipInt(HDC hdc)
{
Graphics graphics(hdc);
// Set the clipping region.
graphics.SetClip(Rect(0, 0, 100, 50));
// Translate the clipping region.
graphics.TranslateClip(40, 30);
// Fill an ellipse that is clipped by the translated clipping region.
SolidBrush brush(Color(255, 255, 0, 0));
graphics.FillEllipse(&brush, 20, 40, 100, 80);
// Draw the outline of the clipping region (rectangle).
Pen pen(Color(255, 0, 0, 0), 2.0f);
graphics.DrawRectangle(&pen, 40, 30, 100, 50);
}
PowerBASIC
SUB GDIP_TranslateClip (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pBrush AS DWORD
LOCAL pPen AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Set the clipping region.
hStatus = GdipSetClipRect(pGraphics, 0, 0, 100, 50, %CombineModeReplace)
' // Translate the clipping region.
hStatus = GdipTranslateClip(pGraphics, 40, 30)
' // Fill an ellipse that is clipped by the translated clipping region.
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pBrush)
hStatus = GdipFillEllipse(pGraphics, pBrush, 20, 40, 100, 80)
' // Draw the outline of the clipping region (rectangle).
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 2, %UnitPixel, pPen)
hStatus = GdipDrawRectangle(pGraphics, pPen, 40, 30, 100, 50)
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pBrush THEN GdipDeleteBrush(pBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipTranslateClip.png)