Nevron Forum

Pin Point the click location

https://www.nevron.com/Forum/Topic7673.aspx

By sudarshan rudrappa - Thursday, April 18, 2013

Hi,

Please let me know how to get the click position of the user on the nevron diagram.
I want to find which place the user has clicked, store the x,y location of it on mouse click event and place an external image in that position.

Thanks,
Sudhi
By Nevron Support - Friday, April 19, 2013

Hi,

You haven't specified whether this is a WinForm or a WebForm project. If it is a WinForm project, then to create a shape and place it on the clicked position in the drawing view you should subscribe to the MouseDown event of the drawing view and in the event handler you should hit test the drawing document to check whether the user has clicked on a free position and then create and add a shape to the document if he has. Here's a simple implementation:

private void OnViewMouseDown(object sender, MouseEventArgs e)

{

      if (e.Button != MouseButtons.Left)

            return;

 

      NPointF location = new NPointF(e.Location);

      NNodeList shapes = view.Document.HitTest(location, -1, NFilters.Shape2D, view.ProvideDocumentHitTestContext());

      if (shapes.Count == 0)

      {

            // Create a circle shape and place it on the clicked position

            location = view.SceneToDevice.InvertPoint(new NPointF(e.Location));

            NShape shape = new NEllipseShape(location.X - 30, location.Y - 30, 60, 60);

            view.Document.ActiveLayer.AddChild(shape);

      }

}

 

If you want an image, you can simply apply an image fill style (or even better use a style sheet) to the newly created shape.