10927 : We are using user drawn links in the Gantt_ASP and it is too hard to the links

Question

We are using user drawn links in the Gantt_ASP and it is too hard to select the links, especially when they are above< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

TimeItems or have a length of 0. Is there a easy way to get a larger

selection area and to have a preference of links above TimeItems?

 

Answer

When investigating this we found that the comment on the UserDrawLink was very brief, and we have extended it to this:


/// <summary>

/// Fired when link with drawstyle=user need to be drawn.

/// There are two passes to link drawing. First there is the normal draw, the e.G is assigned,

/// and you simply draw the Graphics object supplied. Second there is the selection region pass,

/// this is recongnised by e.G==null and e.BoundingRegion is assigned. Now you can fill the region

/// that is used to decide if a click is on a link or not.

/// </summary>

public event UserDrawLinkEvent OnUserDrawLink;

 

This gives that your code can/should look like this to enable the selection shadow of userdrawn timeitemlinks:

 

    private void OnUserDrawLink(Gantt aGantt, UserDrawLinkEventArgs e)

    {

        Rectangle startItemRect = e.Link.Start.DrawRect();

        Point start = new Point();

        start.Y = e.StartPoint.Y;

        start.X = startItemRect.X + (int)(startItemRect.Width * ((double)e.Link.UserReference) / 100.0);

 

        if (e.G==null)

        {

          ASPGantt.Gantt.TimeItemLinks.DrawCommonLinks(e.G, start, e.TargetPoint, e.Link,e.BoundingRegion);

        }

        else

        {

          ASPGantt.Gantt.TimeItemLinks.DrawCommonLinks(e.G, start, e.TargetPoint, e.Link);

        }

    }

 

… This will give a better feedback of clicked links.

Mind you that we currently have no solution for editable timeitems taking precedence over link clicks, other than making those time items not editable.

 

 

And this also explains how you can increase the sensitive of user drawn links when it comes to selection: Just make the region bigger! Try this in the code above:

        if (e.G==null)

        {

          ASPGantt.Gantt.TimeItemLinks.DrawCommonLinks(e.G, start, e.TargetPoint, e.Link,e.BoundingRegion);

          // To make the region bigger so that the selection can be made easier try this:

          Point p1=start;

          Point p2=e.TargetPoint;

          p1.Offset(2,2);

          p2.Offset(2,2);

          ASPGantt.Gantt.TimeItemLinks.DrawCommonLinks(e.G, p1, p2, e.Link, e.BoundingRegion);

         

        }

        else

        {

          ASPGantt.Gantt.TimeItemLinks.DrawCommonLinks(e.G, start, e.TargetPoint, e.Link);

        }

 

 

 

Another question on user drawn links is: Maybe I only want to do some slight change to where the link start or end on a time item, but I do not want to implement the whole Z-style drawing on my own. Can I do that?

 

Yes; go like this

 

        void gantt1_OnUserDrawLink(Gantt aGantt, UserDrawLinkEventArgs e)

        {

            // When drawing links on your own, you may want to be totally free,

            //or you may want to make a few changes and then call the standard drawing:

           

           

            // When sending in null on Link value , the attributes for style and color are taken from these properties

            aGantt.TimeItemLinks.CreationTimeItemLinkDrawStyle=TimeItemLinkDrawStyle.ZStyle;

            aGantt.TimeItemLinks.CreationTimeItemLinkColor=Color.Green;

 

            if (aGantt.MouseMoveKind == MouseMoveKind.none)

                e.TargetPoint = new Point(e.TargetPoint.X, e.TargetPoint.Y + 10);

 

            // When sending null on LinkValue to aGantt.TimeItemLinks.DrawCommonLinks the logic will go only on pixel points

            if (e.G == null)

                aGantt.TimeItemLinks.DrawCommonLinks(e.G, e.StartPoint, e.TargetPoint, e.Link, e.BoundingRegion);

            else

                aGantt.TimeItemLinks.DrawCommonLinks(e.G, e.StartPoint, e.TargetPoint, null);

 

        }

 

 

10956 : Custom links

Question

 

I have created a custom link with the TimeItemLinkDrawStyle.User property but the  OnTimeItemLink_SelectionChanged event doesn’t raise and the UserDrawLinkEventArgs.G property is null in the OnUserDrawLink event when i select a custom link. How could i select a custom link?

Can you help me?

 

Answer

 

The thing is that user drawn links can have any shape, so we need to find a way to describe that shape so that we can detect a selection.

This is done by a two step process; selection region definition and drawing.

 

The selection region definition is done in the in the OnUserDrawLink event when the e.BoundingRegion is set. So, to have a selectable straight line link go like this:

 

< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

        void gantt1_OnUserDrawLink(Gantt aGantt, UserDrawLinkEventArgs e)

        {

          if (e.BoundingRegion!=null)

          {           

            GraphicsPath gp = new GraphicsPath();

            gp.AddLine(e.StartPoint, e.TargetPoint);

            gp.CloseFigure();

            gp.Widen(new Pen(Color.Black,5));

            e.BoundingRegion.Union(new Region(gp));

          }

          else

          {

            e.G.DrawLine(Pens.Red, e.StartPoint, e.TargetPoint);  

          }

        }

 

        void gantt1_OnTimeItemLink_SelectionChanged(TimeItemLinks aLinks, TimeItemLinkArgs args)

        {

          if (args.TimeItemLink.TimeItemLinkDrawStyle==TimeItemLinkDrawStyle.User)

            MessageBox.Show(“User drawn link selected”);

        }