Back to Devexpress

TdxGanttControlChartViewGetTaskColorEvent Type

vcl-dxganttcontrolviewchart-7c9a4d54.md

latest5.0 KB
Original Source

TdxGanttControlChartViewGetTaskColorEvent Type

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

Declaration

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

Parameters

NameTypeDescription
SenderTdxGanttControlChartView

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):

delphi
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;
cpp
{
void __fastcall TMyForm::FormCreate(TObject *Sender)
{ // Loads a chart from the specified XML file
  dxGanttControl1->LoadFromFile("C:/Users/Public/Documents/DevExpress/VCL/Demos/ExpressGantt Control/Data/SoftwareDevelopment.xml");
}
//---------------------------------------------------------------------------
void __fastcall TMyForm::dxGanttControl1ViewChartGetTaskColor(TdxGanttControlChartView *Sender,
          TdxGanttControlTask *ATask, TColor &AColor)
{
// Checks if the inspected task exists and compares its date with the current date
if (ATask != NULL && ATask->Finish < Now()) 
  {
      // Fills outdated tasks with the red color
      AColor = clRed;
  }
}

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:

delphi
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;
cpp
void __fastcall TBaselinesDemoMainForm::GanttControlViewChartGetTaskBaselineColor(TdxGanttControlChartView *Sender,
          TdxGanttControlTask *ATask, TColor &AColor)
{ // Searches a task baseline by its number
  TdxGanttControlTaskBaseline* 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 != NULL) && (ABaseline->Finish - ABaseline->Start < ATask->Finish - ATask->Start))
  {
    // Fills all baselines that meet the specified conditions with the red color
    AColor = clRed;
  }
}

See Also

OnGetLinkColor

TdxGanttControlTimelineView.OnGetTaskColor

dxGanttControlViewChart Unit