Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ContextMenu on Links (Read 1881 times)
Dominic Hoffmann
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 18
Joined: Mar 19th, 2013
ContextMenu on Links
Mar 20th, 2013 at 10:07am
Print Post  
Hi there,

i want to display a contextmenu on every Link inside my Diagram.

After creating the link, i am assigning a new instance of Controls.contextmenu.

i implemented a little routine inside MouseRightButtonDown
to change the brush to blue, after right click at this link.

Code (C++)
Select All
        private DiagramLinkCollection formerLinks = new DiagramLinkCollection();

        private void ChangeLinkStroke(DiagramLinkCollection lc,
            Brush brush)
        {
            ChangeLinkStroke(lc, brush, null);
        }
        private void ChangeLinkStroke(DiagramLinkCollection lc,
            Brush brush,
            DiagramLinkCollection store)
        {
            foreach (DiagramLink link in lc)
            {
                link.Stroke = brush;
                link.StrokeThickness = 1;
                link.HeadStroke = brush;

                if (store != null)
                {
                    link.StrokeThickness = 3;
                    store.Add(link);
                }
            }
        }

        private void flowchart_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            System.Windows.Point p = Mouse.GetPosition(Element);

            System.Windows.IInputElement inp = Element.InputHitTest(p);
            DiagramLink link = inp as DiagramLink;
            if (link != null)
            {
                ChangeLinkStroke(formerLinks, Brushes.Black);
                formerLinks.Clear();
                DiagramLinkCollection lc = new DiagramLinkCollection();
                lc.Add(link);
                ChangeLinkStroke(lc, Brushes.Blue, formerLinks);
            }
        } 



So far no problem.
But now i really have to hit the link with the right mouse button.
A bit too far left or right and i won't get any result the Link got clicked by right mouse button.

So i thought, let's increase the distance a hit gets recognized by setting diagram.LinkHitDistance, but that only seems to have effects on left button clicks.
So how could i reach that for right clicks?

Thanks,
Dominic
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ContextMenu on Links
Reply #1 - Mar 20th, 2013 at 10:40am
Print Post  
Hi,

You can show the context menu from a LinkClicked event handler. If you prefer MouseRightButtonDown, call diagram.GetLinkAt(e.GetPosition(diagram.DocumentPlane)) to find the correct link.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Dominic Hoffmann
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 18
Joined: Mar 19th, 2013
Re: ContextMenu on Links
Reply #2 - Mar 20th, 2013 at 10:56am
Print Post  
Hi,

thank you. Works great and it is excactly what i was looking for.
great.

- Dominic
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint