Pen::SetDashPattern method (gdipluspen.h)
The Pen::SetDashPattern method sets an array of custom dashes and spaces for this Pen object.
Syntax
Status SetDashPattern(
[in] const REAL *dashArray,
[in] INT count
);
Parameters
[in] dashArray
Type: const REAL*
Pointer to an array of real numbers that specifies the length of the custom dashes and spaces. All elements in the array must be positive real numbers.
[in] count
Type: INT
Integer that specifies the number of elements in the dashArray array. The integer must be greater than 0 and not greater than the total number of elements in the array.
Return value
Type: Status
If the method succeeds, it returns Ok, which is an element of the Status enumeration.
If the method fails, it returns one of the other elements of the Status enumeration.
Remarks
This method will set the DashStyle enumeration for this Pen object to DashStyleCustom.
The elements in the dashArray array set the length of each dash and space in the dash pattern. The first element sets the length of a dash, the second element sets the length of a space, the third element sets the length of a dash, and so forth.
The length of each dash and space in the dash pattern is the product of the element value in the array and the width of the Pen object.
Examples
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.
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);
}
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows XP, Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | gdipluspen.h (include Gdiplus.h) |
Library | Gdiplus.lib |
DLL | Gdiplus.dll |