Skip to main content

TdxGanttControlChartViewGetTaskColorEvent Type

The color-related procedural type for tasks and their baselines in the Chart View.

Declaration

TdxGanttControlChartViewGetTaskColorEvent = procedure(Sender: TdxGanttControlChartView; ATask: TdxGanttControlTask; var AColor: TColor) of object;

Parameters

Name Type Description
Sender TdxGanttControlChartView

The Chart View that raised the event.

ATask TdxGanttControlTask

In the OnGetTaskColor event: The task whose color is about to be changed. This parameter is nil (in Delphi) or nullptr (in C++Builder) if a user creates a task in the chart area with the mouse.

In the OnGetTaskBaselineColor event: The task whose baseline’s color is about to be changed.

AColor TColor

A system palette color.

Remarks

Task Color Change

The following code example demonstrates how to use the OnGetTaskColor event to color all outdated tasks in the Chart View with the red color (clRed):

procedure TMyForm.FormCreate(Sender: TObject);
begin
  // Loads a chart from the specified XML file
  dxGanttControl1.LoadFromFile('C:\Users\Public\Documents\DevExpress\VCL\Demos\ExpressGantt Control\Data\SoftDev.xml');
end;

procedure TMyForm.dxGanttControl1ViewChartGetTaskColor(
  Sender: TdxGanttControlChartView; ATask: TdxGanttControlTask;
  var AColor: TColor);
begin
  // Checks if the inspected task exists and compares its date with the current date
  if (ATask <> nil) and (ATask.Finish < Now) then
    // Fills outdated tasks with the red color
    AColor := clRed;
end;

Baseline Color Change

You can open the installed Baselines Demo and modify its code. The demo is available by the following path:

Delphi
C:\Users\Public\Documents\DevExpress\VCL\Demos\ExpressGantt Control\Delphi\BaselinesDemo\
C++Builder
C:\Users\Public\Documents\DevExpress\VCL\Demos\ExpressGantt Control\CBuilder\BaselinesDemo\

The following code example demonstrates how to use the OnGetTaskBaselineColor event to color a baseline in the Chart View with the red color (clRed) if actual dates of its task are shifted:

procedure TBaselinesDemoMainForm.GanttControlViewChartGetTaskBaselineColor(
  Sender: TdxGanttControlChartView; ATask: TdxGanttControlTask;
  var AColor: TColor);
var
  ABaseline: TdxGanttControlTaskBaseline;
begin
  // Searches a task baseline by its number  
  ABaseline := ATask.Baselines.Find(GanttControl.ViewChart.BaselineNumber);
  // Checks if the inspected baseline exists and compares its dates with the associated task's actual dates
  if (ABaseline <> nil) and (ABaseline.Finish - ABaseline.Start < ATask.Finish - ATask.Start) then
    // Fills all baselines that meet the specified conditions with the red color
    AColor := clRed;
end;
See Also