private static Drawing.Point GetPinPositionForCorner(XFormData input_xfrm, Drawing.Point new_lower_left, VisioAutomation.Scripting.Layout.SnapCornerPosition corner) { var size = new Drawing.Size(input_xfrm.Width, input_xfrm.Height); var locpin = new Drawing.Point(input_xfrm.LocPinX, input_xfrm.LocPinY); switch (corner) { case VisioAutomation.Scripting.Layout.SnapCornerPosition.LowerLeft: { return(new_lower_left.Add(locpin.X, locpin.Y)); } case VisioAutomation.Scripting.Layout.SnapCornerPosition.UpperRight: { return(new_lower_left.Subtract(size.Width, size.Height).Add(locpin.X, locpin.Y)); } case VisioAutomation.Scripting.Layout.SnapCornerPosition.LowerRight: { return(new_lower_left.Subtract(size.Width, 0).Add(locpin.X, locpin.Y)); } case VisioAutomation.Scripting.Layout.SnapCornerPosition.UpperLeft: { return(new_lower_left.Subtract(0, size.Height).Add(locpin.X, locpin.Y)); } default: { throw new System.ArgumentOutOfRangeException(nameof(corner), "Unsupported corner"); } } }
public static void SnapCorner(IVisio.Page page, TargetShapeIDs target, Drawing.Size snapsize, VisioAutomation.Scripting.Layout.SnapCornerPosition corner) { // First caculate the new transforms var snap_grid = new SnappingGrid(snapsize); var input_xfrms = XFormData.Get(page, target); var output_xfrms = new List <VisioAutomation.Drawing.Point>(input_xfrms.Count); foreach (var input_xfrm in input_xfrms) { var old_rect = input_xfrm.GetRectangle(); var old_lower_left = old_rect.LowerLeft; var new_lower_left = snap_grid.Snap(old_lower_left); var new_pin_position = ArrangeHelper.GetPinPositionForCorner(input_xfrm, new_lower_left, corner); var output_xfrm = new VisioAutomation.Drawing.Point(new_pin_position.X, new_pin_position.Y); output_xfrms.Add(output_xfrm); } ModifyPinPositions(page, target.ShapeIDs, output_xfrms); }