How to get x,y value of mouse when dragging and dropping in diagram.

Hi~

I am coding the drag drop of the diagram.



The left side of the screen is the editControl.
Select text in editcontrol and drag it to diagram. Then a node is created.
It would be nice if we could know the position value of the mouse like MouseEvent, but unfortunately there is no mouse position value in DragEvent.
I couldn't even find it in the diagram object.
So I made a calculation formula with the found values.

int x = e.X - diagram1.AccessibilityObject.Bounds.Location.X + (int)diagram1.Origin.X;
int y = e.Y - diagram1.AccessibilityObject.Bounds.Location.Y + (int)diagram1.Origin.Y;

It works well.
But when you zoom, the calculation is wrong.
I think it's because of the origin value.

Is there a way to know the last mouse position value regardless of zoom?


4 Replies 1 reply marked as answer

AR Aravind Ravi Syncfusion Team January 11, 2021 12:57 PM UTC

Hi Nam, 
 
We are validating your requirements and update you with more details on January 13th 2020. 
 
Regards 
Aravind Ravi 



AR Aravind Ravi Syncfusion Team January 14, 2021 04:04 AM UTC

Hi Nam, 

Could you please confirm us whether you want node’s position after drag and dropped the nodes in the diagram. If yes, when we drag and drop the node from palette to diagram, NodeCollectionChange event gets triggered. In that event by using the evtArgs.Element we can find which element gets dropped in the diagram. After get the element, through node’s PinPoint position, we can find the dropped position of the node. Please refer to the below code snippet 

private void EventSink_NodeCollectionChanged(CollectionExEventArgs evtArgs) 
       
            if (evtArgs.Element is Node) 
           
                PointF point1 = (evtArgs.Element as Node).PinPoint; 
           
       

Regards 
Aravind Ravi 



NK nam ki hun January 19, 2021 12:52 AM UTC

Thanks for answering my question.
But you seem to have misunderstood the intention of my question.
I don't want to find the point of the dropped node.
I want to find the point of the mouse when dropping text.
That way, I can create a node at the mouse position.
I want to find the correct drop point when zooming or moving a document.
Please answer again.
Thank you.


NG Naganathan Ganesh Babu Syncfusion Team January 19, 2021 12:12 PM UTC

Hi Nam, 
 
We suggest you to diagram’s “Magnification” to find our scale value once zoom the diagram. Then you can find out the mouse location based on the scale value. Please refer to the below modified code example. 
 
Code example: 
 
[C#] 
 
float scale = diagram1.Magnification / 100; 
int x = (int)((e.X - diagram1.AccessibilityObject.Bounds.Location.X + (int)diagram1.Origin.X) * scale); 
int y = (int)((e.Y - diagram1.AccessibilityObject.Bounds.Location.Y + (int)diagram1.Origin.Y) * scale);  
 
Regards, 
 
Naganathan K G 


Marked as answer
Loader.
Up arrow icon