Author Topic: GDI+: GdipSetPenDashStyle  (Read 3265 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
GDI+: GdipSetPenDashStyle
« on: July 03, 2008, 03:00:19 AM »

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.

C++

Code: [Select]
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);
}

PowerBASIC

Code: [Select]
SUB GDIP_SetPenDashStyle (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPen AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a pen.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 255), 15, %UnitWorld, pPen)

   ' // Set the dash style for the pen, and draw a dashed line.
   hStatus = GdipSetPenDashStyle(pPen, %DashStyleDash)
   hStatus = GdipDrawLineI(pGraphics, pPen, 0, 50, 400, 150)

   ' // Reset the dash style for the pen, and draw a second line.
   hStatus = GdipSetPenDashStyle(pPen, %DashStyleDot)
   hStatus = GdipDrawLineI(pGraphics, pPen, 0, 80, 400, 180)

   ' // Reset the dash style for the pen, and draw a third line.
   hStatus = GdipSetPenDashStyle(pPen, %DashStyleDashDot)
   hStatus = GdipDrawLineI(pGraphics, pPen, 0, 110, 400, 210)

   ' // Cleanup
   IF pPen THEN GdipDeletePen(pPen)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB


« Last Edit: August 07, 2011, 09:09:50 PM by José Roca »