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”);

        }

Leave a Reply