10888 : I would like to apply a vertical stripe to a specific day (or days)

Question

I would like to apply a ‘vertical stripe’ to a specific day (or days), I want to use this to show non working (or holidays) using the same technique you use for painting your vertical stripes. How can I achieve this please.

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 Gantt.DateScaler.TimeToPixel method.

So in pseudo code I would go like this:

In the implementation of the OnTimeItemAreaPaintBackground event

int numberOfDaysOnScreen=Round(Gantt.StopTime-Gantt.StartTime)
for i=0 to numberOfDaysOnScreen-1 do
begin
  DateTime oneDay=Gantt.StartTime+i
  Color c=GetColorForThisDay(oneDay)
  int PixelForStartOfDay=Gantt.DateScaler.TimeToPixel(Trunc(oneDay))
  int PixelForEndOfDay=Gantt.DateScaler.TimeToPixel(Trunc(oneDay)+1)
  DrawColoredRectangle(PixelForStartOfDay,0,PixelForEndOfDay,Gantt.Height)
end

 

Leave a Reply