To allow free movement until a drop happens, use this replacement DraggingTool:
public class SnapOnDropDraggingTool : DraggingTool {
public SnapOnDropDraggingTool() {
this.DragOverSnapArea = DragOverSnapArea.None;
}
public override void DoDrop(DragEventArgs e) {
this.DragOverSnapArea = DragOverSnapArea.DiagramAndNodes;
base.DoDrop(e);
this.DragOverSnapArea = DragOverSnapArea.None;
}
}
It’s always the Node.Location point that is lined up when snapping to some grid cell point.
Node.DragOverSnapCellSize is useful when a stationary object is used for snapping. For example, the Planogram sample uses that for the “Racks” and the “Shelves”. But I think you’re asking about having individual Nodes snap differently.
So I think you need to override DraggingTool.ComputeMove. This provides the most general control over where any Node goes. For your information, it is implemented as follows:
protected virtual Point ComputeMove(Node n, Point newloc, Dictionary<Part, Info> draggedparts) {
if (n == null) return newloc;
Point pt = newloc;
Node snapper = this.CurrentSnapper;
// only consider snapping to nodes if DragOverSnapArea includes Nodes
if (snapper != null && (this.DragOverSnapArea&DragOverSnapArea.Nodes) != 0 && ConsiderSnapTo(n, newloc, snapper, draggedparts)) {
pt = SnapTo(n, newloc, snapper, draggedparts);
}
// only consider diagram snapping if there's no SNAPPER node and DragOverSnapArea includes Diagram
if (snapper == null && (this.DragOverSnapArea&DragOverSnapArea.Diagram) != 0) {
pt = SnapTo(n, newloc, null, draggedparts);
}
Point min = n.MinLocation;
Point max = n.MaxLocation;
return new Point(Math.Max(min.X, Math.Min(pt.X, max.X)), Math.Max(min.Y, Math.Min(pt.Y, max.Y)));
}
However, I am guessing that you don’t care about trying to snap a Node according to another Node, the way that the Planogram sample does. So really the functionality you need to implement is:
protected override Point ComputeMove(Node n, Point newloc, Dictionary<Part, Info> draggedparts) {
if (n == null) return newloc;
Point pt = newloc;
if (this.DragOverSnapArea & DragOverSnapArea.Diagram) != 0) {
// adjust pt.X and pt.Y so that node n is lined up the way that you want
. . .
}
Point min = n.MinLocation;
Point max = n.MaxLocation;
return new Point(Math.Max(min.X, Math.Min(pt.X, max.X)), Math.Max(min.Y, Math.Min(pt.Y, max.Y)));
}