The following example creates an array of real numbers. The code then creates a
Pen object, sets the dash pattern based on the array, and then draws the custom dashed line.
C++
VOID Example_SetDashPattern(HDC hdc)
{
Graphics graphics(hdc);
// Create and set an array of real numbers.
REAL dashVals[4] = {
5.0f, // dash length 5
2.0f, // space length 2
15.0f, // dash length 15
4.0f}; // space length 4
// Create a Pen object.
Pen pen(Color(255, 0, 0, 0), 5);
// Set the dash pattern for the custom dashed line.
pen.SetDashPattern(dashVals, 4);
// Draw the custom dashed line.
graphics.DrawLine(&pen, 5, 20, 405, 200);
}
PowerBASIC
SUB GDIP_SetPenDashArray (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPen AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create and set an array of real numbers.
DIM dashVals(3) AS SINGLE
ARRAY ASSIGN dashVals() = 5.0!, 2.0!, 15.0!, 4.0!
' // Create a Pen object.
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 5, %UnitWorld, pPen)
' // Set the dash pattern for the custom dashed line.
hStatus = GdipSetPenDashArray(pPen, dashVals(0), 4)
' // Draw the custom dashed line.
hStatus = GdipDrawLineI(pGraphics, pPen, 5, 20, 405, 200)
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipSetPenDashArray.png)