The following example creates a
Pen object, sets the dash style, and draws a line. The code then resets the dash style, draws a second line, resets dash style again, and draws a third line.
C++
VOID Example_SetDashStyle(HDC hdc)
{
Graphics graphics(hdc);
// Create a Pen object.
Pen pen(Color(255, 0, 0, 255), 15);
// Set the dash style for the pen, and draw a dashed line.
pen.SetDashStyle(DashStyleDash);
graphics.DrawLine(&pen, 0, 50, 400, 150);
// Reset the dash style for the pen, and draw a second line.
pen.SetDashStyle(DashStyleDot);
graphics.DrawLine(&pen, 0, 80, 400, 180);
// Reset the dash style for the pen, and draw a third line.
pen.SetDashStyle(DashStyleDashDot);
graphics.DrawLine(&pen, 0, 110, 400, 210);
}
PowerBASIC
SUB GDIP_SetPenDashStyle (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPen AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create a pen.
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 255), 15, %UnitWorld, pPen)
' // Set the dash style for the pen, and draw a dashed line.
hStatus = GdipSetPenDashStyle(pPen, %DashStyleDash)
hStatus = GdipDrawLineI(pGraphics, pPen, 0, 50, 400, 150)
' // Reset the dash style for the pen, and draw a second line.
hStatus = GdipSetPenDashStyle(pPen, %DashStyleDot)
hStatus = GdipDrawLineI(pGraphics, pPen, 0, 80, 400, 180)
' // Reset the dash style for the pen, and draw a third line.
hStatus = GdipSetPenDashStyle(pPen, %DashStyleDashDot)
hStatus = GdipDrawLineI(pGraphics, pPen, 0, 110, 400, 210)
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipSetPenDashStyle.png)