Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Determine right-clicked node (Read 2651 times)
JB
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Jan 20th, 2009
Determine right-clicked node
Feb 18th, 2009 at 3:31pm
Print Post  
Hi Stoyan,
How do I determine which node was right-clicked? The right-clicked node is not necessarily the Diagram.ActiveItem.

I have a ContextMenuStrip on my DiagramView but want to change the content of the menustrip depending on the node that right-clicked on.

Many thanks,
Johan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Determine right-clicked node
Reply #1 - Feb 18th, 2009 at 3:39pm
Print Post  
Hi,

You could handle the NodeClicked event, check if e.MouseButton == MouseButton.Right, and if so show the context menu with its content modified as necessary.

If you prefer to show the menu from DiagramView.MouseDown event handler, call ClientToDoc to get the diagram coordinates of the mouse pointer, and then GetNodeAt().

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


I love YaBB 1G - SP1!

Posts: 8
Joined: Jan 20th, 2009
Re: Determine right-clicked node
Reply #2 - Feb 19th, 2009 at 7:48am
Print Post  
Hi Stoyan,
Thanks for the reply. The problem is I'm already handling the contextMenuStrip_ItemClicked event. It is in this event that I need to get the node that was right-clicked. There isn't maybe a property to indicate which node had the "mouse over", something similar to ActiveItem? When one moves the mouse over a Node the display of the Node changes so I'm sure there must be a way?

Another option would be to assign the contectMenuStrip to a Node but I couldn't find a way to do this so I had to assigned it to the DiagramView.


Many thanks,
Johan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Determine right-clicked node
Reply #3 - Feb 19th, 2009 at 8:32am
Print Post  
Hi Johan,

You could assign the clicked node to the ContextMenuStrip.Tag, or just save it in a field of the form class.

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


I love YaBB 1G - SP1!

Posts: 8
Joined: Jan 20th, 2009
Re: Determine right-clicked node
Reply #4 - Feb 19th, 2009 at 11:31am
Print Post  
Hi Stoyan,
I'm now using the NodeClicked event and store the node in a class variable for later use. This is working great but because the contextMenuStrip_ItemClicked event fires before the NodeClicked event I now have to programmatically show the contextMenuStrip in the NodeClicked event.

I want to show the menuStrip at the same position as the node but I have tried everything to get the correct X and Y coordinates but my menuStrip never opens at the correct place. How do I get the correct point?

This code gets it very close but not 100%:
       private void diagramProcessFlow_NodeClicked(object sender, NodeEventArgs e)
       {
           // Make sure we have clicked a Shape Node and display the menu
           if (e.MouseButton == MouseButton.Right && (e.Node is ShapeNode))
           {
               clickedNode = e.Node;
               contextMenuStripFeatures.Show(pnlProcessFlow, new Point(Convert.ToInt32(e.Node.Bounds.X), Convert.ToInt32(e.Node.Bounds.Y)));
           }
       }

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Determine right-clicked node
Reply #5 - Feb 19th, 2009 at 11:52am
Print Post  
Hi Johan,

By default Bounds is expressed in millimeters. Use the DiagramView.DocToClient method to get the pixel coordinates relative to the view that correspond to the nodes' diagram coordinates. This should also take care of the scroll position and zoom level.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint