TPen

Fonte: source/classes/pen.prg

Standalone class (no inheritance)

TPen encapsulates a Windows GDI pen object for drawing lines, borders, and outlines. Pens define the color, width, and style (solid, dashed, dotted, etc.) of lines drawn on any device context. TPen is used internally by many FiveWin controls and is also available for direct use in custom painting routines.

Key DATA Members

DATATypeDescription
hPenNumeric (Handle)Windows GDI pen handle
nStyleNumericPen style (PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, etc.)
nWidthNumericPen width in logical units (pixels)
nColorNumericPen color as RGB value
oDeviceObjectOptional device context owner for DPI-aware width scaling

Methods

MethodDescription
New( nStyle, nWidth, nColor, oDevice )Create a new pen. Defaults: PS_SOLID, width 1, CLR_BLACK. When oDevice is provided, width is scaled by DPI.
End()Delete the GDI pen object and release resources. Alias for Release().

Pen Styles

ConstantValueDescription
PS_SOLID0Solid line (default)
PS_DASH1Dashed line (valid only when width is 1)
PS_DOT2Dotted line (valid only when width is 1)
PS_DASHDOT3Alternating dash-dot pattern
PS_DASHDOTDOT4Dash-dot-dot pattern
PS_NULL5Invisible pen
PS_INSIDEFRAME6Solid pen that draws inside the bounding frame

Example

#include "FiveWin.ch"

function Main()

   local oWnd, oPen

   DEFINE WINDOW oWnd TITLE "TPen Demo" SIZE 400, 300

   oWnd:bPainted = {| hDC |
      // Create a red pen with width 2
      DEFINE PEN oPen WIDTH 2 COLOR CLR_RED

      // Draw a line from top-left to bottom-right
      MoveTo( hDC, 50, 50 )
      LineTo( hDC, 350, 250, oPen:hPen )

      oPen:End()
      }

   ACTIVATE WINDOW oWnd CENTERED

return nil

Notes

Veja Também