Hi,
I'd like to achieve some auto-aligning similar to the WinForms Designer of VS, as in:
when dragging a node, and...
- its current Y-Coordinate is near the Y-Coordinate of some other node, snap to that Y-Coord. and display a helper line across the diagram through the top of that node.
- its current Y-Center is near the Y-Center of some other node, snap the center to that Y-Coord. and display a helper line across the diagram through the Y-Center of that node.
- same for Bottom
- similarly for X-Coordinates (Left, Center, Right).
This will help aligning Nodes horizontally and vertically. Is this implemented? (I think Diagram.AutoAlignNodes works differently, right?). So what would I need to do to achieve this? In the NodeModifying-Event, I seem not to be able to change the bounds of the dragged node:
private void HandlesNodeModifying(object sender, NodeValidationEventArgs args)
{
const float Delta = 1f;
var node = args.Node;
var db = this.Diagram.Bounds;
var same = this.Diagram.Nodes.Except(new[] { args.Node })
.FirstOrDefault(n => Math.Abs(n.Bounds.Y - node.Bounds.Y) < Delta);
if (same!= null)
{
node.Bounds = new RectangleF(node.Bounds.X, same.Bounds.Y, node.Bounds.Width, node.Bounds.Height);
}
same= this.Diagram.Nodes.Except(new[] { args.Node })
.FirstOrDefault(n => Math.Abs(n.Bounds.X - node.Bounds.X) < Delta);
if (same!= null)
{
node.Bounds = new RectangleF(same.Bounds.X, node.Bounds.Y, node.Bounds.Width, node.Bounds.Height);
}
}
PS: sorry for the amount of questions lately