We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Mouse events for DiagramControl

Good Morning,
I'm using version of WPF diagram.
I'm trying to hook mouse events like MouseDown, MouseLeftButtonDown but with the canonical operation
DiagramControlMain.MouseLeftButtonDown += DiagramControlMainOnMouseLeftButtonDown;

the DiagramControlMainOnMouseLeftButtonDown handler is not call on the related action of mouse.

I tried also with the provided DiagramBuilder example project with the same result.

Where's my error?

Best Regards

Domenico Mozzone

6 Replies

DM Domenico Mozzone January 10, 2014 04:41 PM UTC

I'm sorry I forgot to ask the way to change the Mouse Cursor on DiagramControl.
Thanks in advance
Best regards

DM Domenico Mozzone January 10, 2014 05:14 PM UTC

..last thing and then I hope to stop boring you.
How can I get coordinates in the Diagram reference system of a mouse click (actually a double click as is the only event I was able to connect)?
I tried 
var position = mouseButtonEventArgs.GetPosition(null);
but such position seems to be referred to the top left corner.

Best regards

DM Domenico Mozzone January 13, 2014 07:52 AM UTC

don't mind the last question, I solved.
var position = mouseButtonEventArgs.GetPosition(DiagramView);
                if (this.HorizontalRuler.Visibility == Visibility.Visible)
                    position.Y -= this.HorizontalRuler.ActualHeight;
                if (this.VerticalRuler.Visibility == Visibility.Visible)
                    position.X -= this.VerticalRuler.ActualWidth;

Thank you

PA Parthiban A Syncfusion Team January 16, 2014 06:29 AM UTC

Hi Domenico,

Diagram controls MouseLeftButtonDown event is used for internal purpose. So you can use Addhandler method to hook new event handler. Kindly find the code snippet below,

DiagramControl diagramcontrol=new DiagramControl();

            diagramcontrol.AddHandler(MouseLeftButtonDownEvent, new RoutedEventHandler(OnMouseLeftButtonDown), true);


private void OnMouseLeftButtonDown(object sender, RoutedEventArgs e)


   System.Windows.Forms.Cursor.Position = new System.Drawing.Point(0, 0);


To change the mouse cursor dynamically, kindly find the code snippet below

System.Windows.Forms.Cursor.Position = new System.Drawing.Point(0, 0);

Note : Need to add System.Windows.Forms and System.Drawing dll


Parthiban A.

DM Domenico Mozzone January 16, 2014 09:38 AM UTC

Hi Parthiban,
Thank you for your help.
My need is to:
1. Change the mouse pointer shape from default to cross for example and viceversa,
2. Intercept the mouseDown of left button (solved with your help)
3. Get mouse coordinates in the(x,y) diagram reference system

Number 2 is ok, thanks to your help, but 1 and 3 I think that I didn't succeed in explaning the requirements.
Hope that now is clearer

Kind regards.
Domenico M

PA Parthiban A Syncfusion Team January 21, 2014 06:14 AM UTC

Hi Domenico,

Kindly find the responses below,





Change the mouse pointer shape from default to cross for example and viceversa,

We can change the pointer shape by setting type for Cursor property. But couldn’t set pointer type for diagram control objects like node, connector, diagram page. Since those are set by internally. However we can set cursor for any framework element. We have created sample in which set button as node, while drag and drop from the palette. When mouse over that button, cursor changed to Hand.

For more information please refer the provided sample.


Code Snippet:

(sender as Button).Cursor = Cursors.Hand;



Get mouse coordinates in the(x,y) diagram reference system

Mouse.GetPosition method will return the mouse co-ordinates with respect to the IInputElement. We have created a sample, which will show the mouse co-ordinates while double clicking on the diagram control.


void view_MouseDoubleClick(object sender, MouseButtonEventArgs e)

        {    MessageBox.Show(Mouse.GetPosition(view).ToString());




Parthiban A.



Live Chat Icon For mobile
Up arrow icon