This is a migrated thread and some comments may be shown as answers.

Right Click Position When Zoomed

3 Answers 58 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Don
Top achievements
Rank 1
Don asked on 02 Sep 2014, 12:50 AM
When a user right clicks in the diagram when it is zoomed, the mouse position does not match the coordinates of the diagram.

Point p = context.MousePosition;
pastePoint = new Point(zoomFact * p.X, zoomFact * p.Y);
Point mfTestPoint = Application.Current.RootVisual.TransformToVisual(currentDiagram.DocumentPlane).Transform(pastePoint);
 
DiagramNode clickedItem3 = currentDiagram.GetNodeAt(pastePoint, false, true);
CustomDiagramLink clickedItem4 = (CustomDiagramLink)currentDiagram.GetLinkAt(pastePoint, 5, true);

I tried using the zoom factor as a modifier to find the object on the diagram but that doesn't work either. The original version of this method just used the mouse position as the pastePoint and that works fine when not zoomed. How should I handle finding the object that is right clicked so that the context menu can be modified depending on what the user clicks on.

PS this is a deployed application and the version can't be changed. It is currently using version 2.3.0.16766.

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 02 Sep 2014, 01:54 PM
Hi Donald,

The coordinate system of the RadDiagram is not directly related to the application's coordinates. When the diagram is not zoomed the coordinates match but when you zoom there is a noticeable difference based on the zoom factor.

However, the diagram exposes GetTransformedPoint() method that transforms a Point from the screen to a Point from the diagram. 

Point p = context.MousePosition;
var transformedPoint = this.diagram.GetTransformedPoint(mousePos);

A possible approach for finding the object that is right clicked is to listen for the MouseRightButtonDown event of the diagram and in its handler to get the shape that has its IsMouseOver property set to True. Here is an example:

var shapeUnderMouse = this.diagram.Shapes.FirstOrDefault(x => x.IsMouseOver);
if (shape != null)
{
    // execute your logic here
}

Please let me know if this helps.

Regards,
Martin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Don
Top achievements
Rank 1
answered on 02 Sep 2014, 02:39 PM
Can you tell me what version of the control GetTransformedPoint was implemented in? The version that is deployed in that application does not have that method. The version of control we are using is 2.3.0.16766. (Yea I know but it is out of my hands)
0
Don
Top achievements
Rank 1
answered on 02 Sep 2014, 02:41 PM
Never mind. I figured it out and the control does have the method. It appears to work. Thank you.
Tags
Diagram
Asked by
Don
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Don
Top achievements
Rank 1
Share this question
or