The following example creates an array of real numbers and a
Pen object, sets the dash pattern, and draws a custom dashed line. The code then gets the dash pattern currently set for the pen.
C++
VOID Example_GetDashPattern(HDC hdc
{
Graphics graphics(hdc);
// Create a custom dashed pen, and use it to draw a line.
REAL dashVals[4] = {5, 2, 15, 4};
Pen pen(Color(255, 0, 0, 0), 5);
pen.SetDashPattern(dashVals, 4);
graphics.DrawLine(&pen, 5, 20, 405, 200);
// Obtain information about the pen.
INT count = 0;
REAL* dashValues = NULL;
count = pen.GetDashPatternCount();
dashValues = new REAL[count];
pen.GetDashPattern(dashValues, count);
for(INT j = 0; j < count; ++j)
{
// Inspect or use the value in dashValues[j].
}
delete [] dashValues;
}
PowerBASIC
SUB GDIP_GetPenDashArray (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)
' // Obtain information about the pen.
LOCAL count AS LONG
DIM dashValues(0) AS SINGLE
hStatus = GdipGetPenDashCount(pPen, count)
REDIM dashValues(count - 1)
hStatus = GdipGetPenDashArray(pPen, dashValues(0), count)
LOCAL j AS LONG
FOR j = 0 TO count - 1
' // Inspect or use the value in dashValues[j].
OutputDebugString STR$(dashValues(j))
NEXT
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipGetPenDashArray.png)