Mariyana
Mariyana
CC#
Created by Mariyana on 4/9/2025 in #help
winforms c# --> translateTo method
public void TranslateTo(PointF p) { // дали има избрани фигури за преместване if (Selection.Count == 0 || Selection == null) { return; } PointF currentPoint = new PointF(p.X, p.Y); if(lastLocation == null) { lastLocation = currentPoint; return; } // минава през всички избрани фигури foreach (Shape shape in Selection) {
using (Matrix invertMatric = shape.TransformationMatrix.Clone()) { try { invertMatric.Invert(); } catch (Exception ex) { Console.WriteLine($"Error invert {ex.Message}"); } PointF[] pointsArray = new PointF[] {currentPoint,lastLocation}; invertMatric.TransformPoints(pointsArray); PointF localP = pointsArray[0]; PointF localLastLocation = pointsArray[1]; float deltaX = localP.X - localLastLocation.X; float deltaY = localP.Y - localLastLocation.Y; if(!(shape is GroupShape)) { shape.Location = new PointF(shape.Location.X + deltaX, shape.Location.Y + deltaY); }
if (shape is GroupShape group && group.SubShapes != null) { foreach (Shape subShape in group.SubShapes) { if (subShape == null) continue; subShape.Location = new PointF(subShape.Location.X + deltaX, subShape.Location.Y + deltaY); } } } when i have a group , the figures in the group are not moving synchronized
1 replies