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

RadDiagramRuler Get mouse position

2 Answers 25 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Loic
Top achievements
Rank 1
Loic asked on 19 Feb 2021, 02:16 PM

Hi,

Is it possible to retrieve the position of the mouse on the ruler? I would like to display it in decimal in my control.

 

Best Regards,

Michael

2 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 24 Feb 2021, 11:35 AM

Hi Michael,

You can use the MouseMove events of both the RadDiagram and RadDiagramRuler like so:

        private void RadDiagram_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var viewport = this.diagram.Viewport;
            var pos = e.GetPosition(this.diagram);
            this.X.Text = ((pos.X / diagram.Zoom) + viewport.Location.X).ToString();
            this.Y.Text = ((pos.Y / diagram.Zoom) + viewport.Location.Y).ToString();
        }

        private void RadDiagramRuler_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var viewport = this.diagram.Viewport;
            var pos = e.GetPosition(this.diagramRuler);
            this.X.Text = ((pos.X / diagram.Zoom) + viewport.Location.X).ToString();
            this.Y.Text = viewport.Location.Y.ToString(); // if you're using a vertical ruler, you can set the X value instead
        }

You can notice that I use the Zoom and Viewport properties to calculate the offset when zooming is applied. As specified in the comment, you need to set the X and Y values accordingly when using a vertical ruler instead.

Please have a look at the sample project I've prepared and let me know if a similar approach would work at your end.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Loic
Top achievements
Rank 1
answered on 01 Mar 2021, 02:47 PM

Hi,

Thank you for the example code ! It helped to solve my problem.

Best Regards,

Michael

 

Tags
Diagram
Asked by
Loic
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Loic
Top achievements
Rank 1
Share this question
or