Author Topic: GDI+: GdipGetPenDashStyle  (Read 2553 times)

0 Members and 1 Guest are viewing this topic.

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
GDI+: GdipGetPenDashStyle
« on: July 03, 2008, 03:32:15 AM »

The following example creates a Pen object, sets the dash style, and draws a dashed line. The code then gets the dash style, creates a second pen with the dash style of the first pen, and draws a second dashed line.

C++

Code: [Select]
VOID Example_GetDashStyle(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a dashed pen, and use it to draw a dashed line.
   Pen pen(Color(255, 255, 0, 0), 9);
   pen.SetDashStyle(DashStyleDashDot);
   graphics.DrawLine(&pen, 20, 20, 200, 100);

   // Obtain the dash style for the pen.
   DashStyle dashStyle;
   dashStyle = pen.GetDashStyle();

   // Create another pen, and use the same dash style.
   Pen pen2(Color(255, 0, 255, 0), 9);
   pen2.SetDashStyle(dashStyle);

   // Draw a second dashed line.
   graphics.DrawLine(&pen2, 20, 60, 200, 140);
}

PowerBASIC

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

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

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

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

   ' // Obtain the dash style for the pen.
   LOCAL dashStyle AS LONG
   hStatus = GdipGetPenDashStyle(pPen, dashStyle)

   ' // Create another pen, and use the same dash style.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 255, 0), 9, %UnitWorld, pPen2)
   hStatus = GdipSetPenDashStyle(pPen2, dashStyle)

   ' // Draw a second dashed line.
   hStatus = GdipDrawLineI(pGraphics, pPen2, 20, 60, 200, 140)

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

END SUB


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