• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

GDI+: GdipSetPenDashArray

Started by José Roca, July 03, 2008, 02:05:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



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.

C++


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


PowerBASIC


SUB GDIP_SetPenDashArray (BYVAL hdc AS DWORD)

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

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create and set an array of real numbers.
   DIM dashVals(3) AS SINGLE
   ARRAY ASSIGN dashVals() = 5.0!, 2.0!, 15.0!, 4.0!

   ' // Create a Pen object.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 5, %UnitWorld, pPen)

   ' // Set the dash pattern for the custom dashed line.
   hStatus = GdipSetPenDashArray(pPen, dashVals(0), 4)

   ' // Draw the custom dashed line.
   hStatus = GdipDrawLineI(pGraphics, pPen, 5, 20, 405, 200)

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

END SUB