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
| DATA | Type | Default | Description |
|---|---|---|---|
aItems | Array | {} | Array of TGanttItem objects |
nCellWidth | Numeric | 28 | Width of each grid cell in pixels |
nCellHeight | Numeric | 25 | Height of each grid cell in pixels |
nCols | Numeric | 31 | Number of grid columns (typically days in month) |
nRows | Numeric | 6 | Number of grid rows (tasks) |
lGridMonth | Logical | .F. | Show month-day header grid |
bChange | Block | Code block executed when an item is changed | |
bPressed | Block | Code block executed on item press | |
nTopOffset | Numeric | 5 | Top offset for grid rendering |
Methods
| Method | Description |
|---|---|
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:
| Property | Type | Description |
|---|---|---|
nRow | Numeric | Row position of the item |
nStart | Numeric | Start column (typically day number) |
nEnd | Numeric | End column (typically day number) |
nClrBack | Numeric | Background 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
- Use
SetGridMonth( nRows )to display weekday/month headers. nRows determines how many weeks are visible. Without this, the grid shows a plain column-number header. - Items are stored in
aItemsas TGanttItem objects. UseAtItem( nRow, nCol )to locate an item at a specific grid coordinate. - The
bChangecodeblock is triggered when an item is dragged or modified via mouse interaction. The codeblock receives the affected TGanttItem as a parameter. - The control recalculates cell positions on resize via
ReCalculate(), which is automatically called from the Resize method. - Cell dimensions (
nCellWidth,nCellHeight) can be adjusted to fit different display densities or project durations.