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

 

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

Question

Hi, i am currently evaluating phGantTime package and i would like to see is it possible to  a rosters with it. What i need is to be able to display various periods of calendar with several shifts (time periods) in a day..And i need to assign employees to shifts. Also i need to be able to draw holidays and weekends with different colors.

Can you please send me some sample code? Because there are alot of properties, and so far i cant find a way how to customize this top line which displays date

 

Answer

The sample code below draws a green background on Wednesdays and a red background on sunday. This sample is for GTP.NET but you can do the same thing in phGantTimePackage…

    private void gantt1_OnDateScalerPaintBackground(PlexityHide.GTP.OffscreenDraw aOffscreenDraw, PlexityHide.GTP.OffscreenDrawArgs e)< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    {

      DoBack(e.G,gantt1.DateScaler.Height);

    }

    private void gantt1_OnTimeItemAreaPaintBackground(PlexityHide.GTP.OffscreenDraw aOffscreenDraw, PlexityHide.GTP.OffscreenDrawArgs e)

    {

      DoBack(e.G,gantt1.TimeItemArea.Height);

    }

 

    private void DoBack(Graphics G,int aHeight)

    {

      DateTime i=gantt1.DateScaler.StartTime;

      DateTime ii;

      Brush b_sunday=new SolidBrush(Color.Red);

      Brush b_wednesday=new SolidBrush(Color.Green);

      while (i<gantt1.DateScaler.StopTime)

      {

        ii=i.AddDays(1);

       

        int x1=gantt1.DateScaler.TimeToPixel(i.Subtract(i.TimeOfDay));

        int x2=gantt1.DateScaler.TimeToPixel(ii.Subtract(ii.TimeOfDay));

       

        if (i.DayOfWeek==DayOfWeek.Sunday )

          G.FillRectangle(b_sunday,x1,0,x2-x1,aHeight);

        else

        if (i.DayOfWeek==DayOfWeek.Wednesday)

          G.FillRectangle(b_wednesday,x1,0,x2-x1,aHeight);

       

       i=ii;

      }

    }

 

 

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

 

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.

 

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

Question

Hi, i am currently evaluating phGantTime package and i would like to see is it possible to  a rosters with it. What i need is to be able to display various periods of calendar with several shifts (time periods) in a day..And i need to assign employees to shifts. Also i need to be able to draw holidays and weekends with different colors.

Can you please send me some sample code? Because there are alot of properties, and so far i cant find a way how to customize this top line which displays date

 

Answer

The sample code below draws a green background on Wednesdays and a red background on sunday. This sample is for GTP.NET but you can do the same thing in phGantTimePackage…

    private void gantt1_OnDateScalerPaintBackground(PlexityHide.GTP.OffscreenDraw aOffscreenDraw, PlexityHide.GTP.OffscreenDrawArgs e)< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    {

      DoBack(e.G,gantt1.DateScaler.Height);

    }

    private void gantt1_OnTimeItemAreaPaintBackground(PlexityHide.GTP.OffscreenDraw aOffscreenDraw, PlexityHide.GTP.OffscreenDrawArgs e)

    {

      DoBack(e.G,gantt1.TimeItemArea.Height);

    }

 

    private void DoBack(Graphics G,int aHeight)

    {

      DateTime i=gantt1.DateScaler.StartTime;

      DateTime ii;

      Brush b_sunday=new SolidBrush(Color.Red);

      Brush b_wednesday=new SolidBrush(Color.Green);

      while (i<gantt1.DateScaler.StopTime)

      {

        ii=i.AddDays(1);

       

        int x1=gantt1.DateScaler.TimeToPixel(i.Subtract(i.TimeOfDay));

        int x2=gantt1.DateScaler.TimeToPixel(ii.Subtract(ii.TimeOfDay));

       

        if (i.DayOfWeek==DayOfWeek.Sunday )

          G.FillRectangle(b_sunday,x1,0,x2-x1,aHeight);

        else

        if (i.DayOfWeek==DayOfWeek.Wednesday)

          G.FillRectangle(b_wednesday,x1,0,x2-x1,aHeight);

       

       i=ii;

      }

    }