Pen::SetDashStyle method (gdipluspen.h)

The Pen::SetDashStyle method sets the dash style for this Pen object.

Syntax

Status SetDashStyle(
  [in] DashStyle dashStyle
);

Parameters

[in] dashStyle

Type: DashStyle

Element of the DashStyle enumeration that specifies the dash style for this Pen object.

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

The length of the dashes in a dashed line is dependent on the dash style and the width of the Pen object. The length of the space that separates two dashes in a dashed line is equal to the width of the Pen object.

Examples

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.

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); 
}

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

See also

Drawing a Custom Dashed Line

Pen

Pen::GetDashCap

Pen::GetDashOffset

Pen::GetDashPattern

Pen::GetDashPatternCount

Pen::GetDashStyle

Pen::SetDashCap

Pen::SetDashOffset

Pen::SetDashPattern

Pens, Lines, and Rectangles