Profile Picture

get drag and drop events of a shape working

Posted By sandro schimke 13 Years Ago
Author
Message
Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Sandro,

The best way to forbid a shape from dropping on a specific area of the grid is to use the NodeBoundsChanging event of the drawing document’s event sink service:

 

document.EventSinkService.NodeBoundsChanging += new NodeBoundsCancelEventHandler(OnNodeBoundsChanging); 

 

The event is cancelable, so you just have to assign true to the Cancel property of the supplied event args to cancel the shape to move to its new location. Here’s a simple example for the NodeBoundsChanging event handler:

 

 private void OnNodeBoundsChanging(NNodeBoundsCancelEventArgs args)

{

      // The following will be an example area that is not allowed for shapes

      NRectangleF forbiddenArea = new NRectangleF(100, 100, 300, 300);

 

      // Get the shape which bounds has changed

      NShape shape = args.Node as NShape;

      if (shape == null)

            return;

 

      // Check if the shape is dropped on an allowed location

      NRectangleF bounds = args.NewBounds;

      if (forbiddenArea.IntersectsWith(bounds))

      {

            // Cancel the the dragging of the shape

            args.Cancel = true;

      }

}



Best Regards,
Nevron Support Team



sandro schimke
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 1, Visits: 1
Hello,

I'd like to drag a shape and drop it somewhere else on a grid. In the moment I drop it, I'd like to check if it's permitted to drop it there. I think I should use the MouseUp event of the shape in the preview layer. Preview shape and original shape have the same uniqueID, that's how I get the original coordinates. But I don't know how to set the event for the preview shape.

NDrawingView1.PreviewLayer.FireEvents = True
NDrawingDocument1.EventSinkService.Start()
AddHandler NDrawingDocument1.EventSinkService.NodeMouseUp, AddressOf Me.handleMouseUp

With that code I receive events not only for the shapes, but for all MouseUps on the grid.

So, how can I access the preview shape to assign an eventhandler?
Is it actually the right way? DragEnter and DragLeave events of the original shape themself, as I understood, are used for a different challenge.



Similar Topics


Reading This Topic