The following example creates a
GraphicsPath object
path, adds two rectangles to
path, and then draws
path.
C++
VOID Example_AddRectangles(HDC hdc)
{
Graphics graphics(hdc);
RectF rects[] = {RectF(20.0f, 20.0f, 100.0f, 50.0f),
RectF(30.0f, 30.0f, 50.0f, 100.0f)};
GraphicsPath path;
path.AddRectangles(rects, 2);
// Draw the path.
Pen pen(Color(255, 255, 0, 0));
graphics.DrawPath(&pen, &path);
}
PowerBASIC
SUB GDIP_AddPathRectangles (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pPen AS DWORD
DIM rcf(1) AS RECTF
hStatus = GdipCreateFromHDC(hdc, pGraphics)
hStatus = GdipCreatePath(%FillModeAlternate, pPath)
rcf(0).x = 20 : rcf(0).y = 20 : rcf(0).Width = 100 : rcf(0).Height = 50
rcf(1).x = 30 : rcf(1).y = 30 : rcf(1).Width = 50 : rcf(1).Height = 100
hStatus = GdipAddPathRectangles(pPath, rcf(0), 2)
' // Draw the path.
hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 1, %UnitWorld, pPen)
hStatus = GdipDrawPath(pGraphics, pPen, pPath)
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pPath THEN GdipDeletePath(pPath)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipAddPathRectangles.png)