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

RadDiagram PointToScreen and PointToClient accuracy

3 Answers 154 Views
Diagram, DiagramRibbonBar, DiagramToolBox
This is a migrated thread and some comments may be shown as answers.
Hocine
Top achievements
Rank 1
Hocine asked on 25 Jun 2020, 03:30 PM
Hi,

I"m working with RadDiagram where I added several RadDiagramContainerShape and RadDiagramShape. The main container is a RadDiagramContainerShape and it is positioned at (0, 0) according to the RadDiagram.

When I click on the top left corner of the main container, at the red dot in the attached image, the button click is (41,39). Then I use PointToClient to get the position in the RadDiagram and I have (35, -40), knowing that it is supposed to be around (0, 0). Then to make sure of this I calculated the  PointToScreen using the main container location which is (0, 0). The result was (6, 79), but it is supposed to be around the button click (41,39).

In addition, when I drag and drop shapes to my main container it never goes to the cursor position because all what is mentioned above is not accurate.

Is this normal, and what can I do to fix this?
Thanks in advance for your help!

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 30 Jun 2020, 10:58 AM

Hi Hocine,

The diagram container which contains all shapes and connectors can be zoomed (In or Out) and can be panned as well. So, you should transform the Mouse Location to diagram container (named MainPanel) coordinate in this way:

Telerik.WinControls.Layouts.RadMatrix transform = this.radDiagram1.DiagramElement.MainPanel.TotalTransform;
transform.Invert();
var transformedPosition = transform.TransformPoint(e.Location);//e.Location is Mouse Location

For example, you can print out and compare both coordinates: Mouse and Transformed coordinates in the Mouse Down Event:

        private void RadDiagram1_MouseDown(object sender, MouseEventArgs e)
        {
            Console.Write(e.Location + "");

            Telerik.WinControls.Layouts.RadMatrix transform = this.radDiagram1.DiagramElement.MainPanel.TotalTransform;
            transform.Invert();
            var transformedPosition = transform.TransformPoint(e.Location);

            Console.WriteLine(" " + transformedPosition);
        }

I hope this information is useful. 

Regards,
Peter
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Hocine
Top achievements
Rank 1
answered on 30 Jun 2020, 02:55 PM

 

Hi Peter,

 

Knowing that the main container can be zoomed and moved using the pan tool I was able to solve my problem using this small method, note that Viewport is my RadDiagram.

 

   private void SetPoint(DragEventArgs e)
        {
            //Set the location of the drop
            var panOffset = Viewport.DiagramElement.MainPanel.PositionOffset;

            Point pointInViewport = Viewport.PointToClient(new System.Drawing.Point(e.X, e.Y));

            int iRealPositionX = Convert.ToInt32((pointInViewport.X - panOffset.Width) / Viewport.Zoom);
            int iRealPositionY = Convert.ToInt32((pointInViewport.Y - panOffset.Height) / Viewport.Zoom);

            MouseDropPoint = new Point(iRealPositionX, iRealPositionY);
        }

0
Peter
Telerik team
answered on 01 Jul 2020, 11:26 AM

Hi Hocine,

I can confirm that these calculations are looks correct. Also, the way that you get the pan offset is OK.

Let me know if have other questions.

Regards,
Peter
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Diagram, DiagramRibbonBar, DiagramToolBox
Asked by
Hocine
Top achievements
Rank 1
Answers by
Peter
Telerik team
Hocine
Top achievements
Rank 1
Share this question
or