• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipSetPenColor

Started by José Roca, July 02, 2008, 12:09:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a red pen and draws a line. The code then sets the pen's color to blue and draws a second line.

C++


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

   // Create a red pen, and use it to draw a line.
   Pen pen(Color(255, 255, 0, 0), 5);
   graphics.DrawLine(&pen, 0, 0, 200, 100);

   // Change the pen's color to blue, and draw a second line.
   pen.SetColor(Color(255, 0, 0, 255));
   graphics.DrawLine(&pen, 0, 40, 200, 140);
}


PowerBASIC


SUB GDIP_SetPenColor (BYVAL hdc AS DWORD)

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

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a red pen, and use it to draw a line.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 5, %UnitWorld, pPen)
   hStatus = GdipDrawLineI(pGraphics, pPen, 0, 0, 200, 100)

   ' // Change the pen's color to blue, and draw a second line.
   hStatus = GdipSetPenColor(pPen, GDIP_ARGB(255, 0, 0, 255))
   hStatus = GdipDrawLineI(pGraphics, pPen, 0, 40, 200, 140)

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

END SUB