• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

GDI+: GdipSetPenDashStyle

Started by José Roca, July 03, 2008, 03:00:19 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



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++


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


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