10886 : I would like to color columns for certain days in a different color with the phGantTimePackage.

Question

Hi, I’d like to color columns for certain days in a different color with the phGantTimePackage. Could you pleace provide an example on how to achieve this with the OnGantAreaDrawBackground handler?

Thanks!

Answer

In order to do this you must know when a day starts and stops in pixels, this is easily found by sending in a datetime to the IphGantX3.DateToPixel method.

So in pseudo code I would go like this:

int numberOfDaysOnScreen=Round(phGant.Stop-phGant.Start)
for i=0 to numberOfDaysOnScreen-1 do
begin
  DateTime oneDay=phGantt.Start+i
  Color c=GetColorForThisDay(oneDay)
  int PixelForStartOfDay=phGantt.DateToPixel(Trunc(oneDay))
  int PixelForEndOfDay=phGantt.DateToPixel(Trunc(oneDay)+1)
  DrawColoredRectangle(PixelForStartOfDay,0,PixelForEndOfDay,Gantt.Height)
end

10536 : I need is to be able to display various periods of calendar with several shifts (time periods) in a day…

Question

Hello,

My question is the same that was asked in ‘Q10066 – FAQ: I need is to be able to display various periods of calendar with several shifts (time periods) in a day..’.

My problem is that you posted a sample for GTP.Net saying that it would be the same for phGantTimePackage, but I can’t find the OnDateScalerPaintBackground or the OnTimeItemAreaScalerPaintBackground events in the phGantTime OCX.

Which event should I override to be able to paint different weekdays with different colors in the Gantt?

Thank you very much,

Answer

In phGantTimePackage you have these events in the VCL version:

TphGant.OnUserDrawBackground
TphDateScaler.OnUserDrawBackground

In the OCX version the DateScaler OnUserDrawBackground is not currently available (if you need it email support and we can expose it) but you have the phGantX.OnGantAreaDrawBackground to handle the background in the TimeItemArea.