Pen::SetDashOffset method (gdipluspen.h)

The Pen::SetDashOffset method sets the distance from the start of the line to the start of the first dash in a dashed line.

Syntax

Status SetDashOffset(
  [in] REAL dashOffset
);

Parameters

[in] dashOffset

Type: REAL

Real number that specifies the number of times to shift the spaces in a dashed line. Each shift is equal to the length of a space in the dashed line.

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

A positive dashOffset value shifts the first dash forward along the path, and a negative dashOffset value shifts the start of the path forward along the first dash.

Examples

The following example creates a Pen object, sets the dash style, and draws a line. The code then sets the pen's offset value and draws a second line.

VOID Example_SetDashOffset(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a Pen object, set the dash style, and draw a line.
   Pen pen(Color(255, 0, 0, 255), 15);
   pen.SetDashStyle(DashStyleDash);
   graphics.DrawLine(&pen, 0, 50, 400, 50);

   // Set the dash offset value for the pen, and draw a second line.
   pen.SetDashOffset(10);
   graphics.DrawLine(&pen, 0, 80, 400, 80);
}

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::GetDashOffset

Pen::GetDashPattern

Pen::GetDashPatternCount

Pen::GetDashStyle

Pen::SetDashCap

Pen::SetDashPattern

Pen::SetDashStyle

Pens, Lines, and Rectangles