• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipDrawLines

Started by José Roca, June 23, 2008, 04:54:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example draws a sequence of connected lines.

C++


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

   // Create a Pen object.
   Pen blackPen(Color(255, 0, 0, 0), 3);

   // Create an array of PointF objects that define the lines to draw.
   PointF point1(10.0f, 10.0f);
   PointF point2(10.0f, 100.0f);
   PointF point3(200.0f, 50.0f);
   PointF point4(250.0f, 300.0f);

   PointF points[4] = {point1, point2, point3, point4};
   PointF* pPoints = points;

   // Draw the lines.
   graphics.DrawLines(&blackPen, pPoints, 4);
}


PowerBASIC


SUB GDIP_DrawLines (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPen AS DWORD
   DIM   pts(3) AS POINTF

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a Pen
   hStatus = GdipCreatePen1(GDIP_ARGB(255,0, 0, 0), 1, %UnitPixel, pPen)

   ' // Create an array of PointF objects that define the lines to draw.
   pts(0).x = 10.0! : pts(0).y = 10.0!
   pts(1).x = 10.0! : pts(1).y = 100.0!
   pts(2).x = 200.0! : pts(2).y = 50.0!
   pts(3).x = 250.0! : pts(3).y = 300.0!

   ' // Draw the lines
   GdipDrawLines pGraphics, pPen, pts(0), 4

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

END SUB