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

 

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

 

10622 : Time based content in TimeItems

Question

Hi, I would like to draw tick marks inside of a time item. I am using the “OnTimeItem_UserDraw” event and that works fine. An example might be that I would like to have a time item that is 10 minutes long and draw a tick every minute. So when I zoom in and out I the ticks would move around. Is there a way to do this? Perhaps there is a way to get the start and stop time of the region being drawn?

Answer

To draw accurate time based pixels in a user drawn time item you will need to use the DateScaler.PixelToTime and DateScaler.TimeToPixel function.
You can loop from your TimeItems.Start value to TimeItem.Stop. For every second you call DateScaler.TimeToPixel and draw a scale mark.

10388 : Im interested in having some read only time items in a gantt.

Question

I’m interested in having some read only time items in a gantt. These time items are only there to show aggregate data (the total number of hours worked per employee). I don’t want the user to be able to modify them or select them on the gantt. When the user’s mouse hovers over these time items I don’t even want the mouse cursor to change into a hand.

I saw the suggestions in this article:

http://plexityhide.dyndns.org/InstantKB13/Article.aspx?id=10026

Unfortunately, the items are still selectable and the mouse cursor acts as if they are movable items.

Ideally, I’d like to draw information on the “background” of the gantt row at the beginning of each week which states the total number of hours worked for that user for the week. How I was going to accomplish this was adding another layer to the gantt which was databound to a rollup table I calculate which contains this data.

Is there a better way which you would recommend I use to achieve the desired effect?

Answer

To get information into the background that is truly “dead” and allows no interaction I suggest that you implement the OnTimeItemAreaPaintBackground event as described in this article: http://plexityhide.dyndns.org/InstantKB13/Article.aspx?id=10066

You can use the Gantt.DateScaler.TimeToPixel method to translate a time to an exact pixel position so that you place your info on the exact correct place.