TGantt

Source: source/classes/gantt.prg

Inherits from: TControl

TGantt is FiveWin's Gantt chart control for project scheduling and timeline visualization. It displays horizontal bars across a time-based grid, where each bar represents a task with its start and end dates. The control supports interactive mouse operations, month-day grid views, and dynamic recalculation.

Key DATA Members

DATATypeDefaultDescription
aItemsArray{}Array of TGanttItem objects
nCellWidthNumeric28Width of each grid cell in pixels
nCellHeightNumeric25Height of each grid cell in pixels
nColsNumeric31Number of grid columns (typically days in month)
nRowsNumeric6Number of grid rows (tasks)
lGridMonthLogical.F.Show month-day header grid
bChangeBlockCode block executed when an item is changed
bPressedBlockCode block executed on item press
nTopOffsetNumeric5Top offset for grid rendering

Methods

MethodDescription
New( nTop, nLeft, nWidth, nHeight, oWnd, lBorder, lVScroll, lHScroll, nClrFore, nClrBack, bChange, bPressed, oLbx )Create a new TGantt control
Redefine( nId, oWnd, nClrFore, nClrBack, bChange, bPressed, oLbx )Redefine from dialog resource
AddItem( nRow, nStart, nEnd, nClrBack )Add a Gantt bar item to the specified row with start/end columns and background color
AtItem( nRow, nCol )Get the TGanttItem at the specified grid position
SetGridMonth( nRows )Switch to month-day header grid mode. nRows = number of weeks to display.
ReCalculate()Recalculate grid dimensions and item positions after resizing
GridMonth()Draw the month-day header labels
Paint()Render the Gantt grid and all items
Display()Begin paint, call Paint, end paint

TGanttItem

Each bar in the Gantt chart is represented by a TGanttItem object with the following properties:

PropertyTypeDescription
nRowNumericRow position of the item
nStartNumericStart column (typically day number)
nEndNumericEnd column (typically day number)
nClrBackNumericBackground color of the bar

Example: Project Plan Gantt Chart

#include "FiveWin.ch"

function Main()

   local oWnd, oGantt

   DEFINE WINDOW oWnd TITLE "Project Plan" SIZE 800, 400

   @ 10, 10 GANTT oGantt SIZE 760, 340 OF oWnd ;
      CHANGE { |oItem| MsgInfo( "Item changed: Row " + Str( oItem:nRow ) ) }

   // Configure month-day grid for a 4-week view
   oGantt:SetGridMonth( 4 )
   oGantt:nCols := 28

   // Add tasks (row, start_day, end_day, color)
   oGantt:AddItem( 1, 1,  5, CLR_HRED )
   oGantt:AddItem( 2, 3,  10, CLR_HBLUE )
   oGantt:AddItem( 3, 6,  18, CLR_HGREEN )
   oGantt:AddItem( 4, 12, 22, RGB( 255, 165, 0 ) )
   oGantt:AddItem( 5, 15, 28, CLR_HMAGENTA )

   ACTIVATE WINDOW oWnd CENTERED

return nil

Notes

See Also