The following example creates two
Pen objects and sets the alignment for one of the pens. The code then draws two lines using each of the pens.
C++
VOID Example_SetAlignment(HDC hdc)
{
Graphics graphics(hdc);
// Create a black and a green pen.
Pen blackPen(Color(255, 0, 0, 0), 1);
Pen greenPen(Color(255, 0, 255, 0), 15);
// Set the alignment of the green pen.
greenPen.SetAlignment(PenAlignmentInset);
// Draw two ellipses using each pen.
graphics.DrawEllipse(&greenPen, 0, 0, 100, 200);
graphics.DrawEllipse(&blackPen, 0, 0, 100, 200);
}
PowerBASIC
SUB GDIP_SetPenMode (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pBlackPen AS DWORD
LOCAL pGreenPen AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create a black and a green pen.
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1, %UnitWorld, pBlackPen)
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 255, 0), 15, %UnitWorld, pGreenPen)
' // Set the alignment of the green pen.
hStatus = GdipSetPenMode(pGreenPen, %PenAlignmentInset)
' // Draw two ellipses using each pen.
hStatus = GdipDrawEllipseI(pGraphics, pGreenPen, 0, 0, 100, 200)
hStatus = GdipDrawEllipseI(pGraphics, pBlackPen, 0, 0, 100, 200)
' // Cleanup
IF pBlackPen THEN GdipDeletePen(pBlackPen)
IF pGreenPen THEN GdipDeletePen(pGreenPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
The following illustration shows the output of the preceding code.
(http://www.jose.it-berater.org/captures/GdipSetPenMode.png)