public void MouseLeftButtonUp_CreateArrow(object sender, MouseButtonEventArgs e) { canvas.MouseMove -= MouseMove_ArrowDrawing; if (classBox is ClassBox) { Point classBoxPoint = classBox.TransformToAncestor(canvas).Transform(new Point(0, 0)); Point pt = new Point(classBoxPoint.X + classBox.ActualWidth / 2, classBoxPoint.Y + classBox.ActualHeight / 2); classBox.linkPoint = pt; arrow.X2 = pt.X; arrow.Y2 = pt.Y; classBox.arrowLinesTo.Add(arrow); } else { canvas.Children.Remove(arrow); arrow = null; } foreach (object obj in canvas.Children) { if (obj is ClassBox) { ClassBox cb = (ClassBox)obj; cb.MouseLeftButtonDown -= MouseLeftButtonDown_CreateArrow; cb.MouseLeftButtonDown += MouseLeftButtonDown_groupClassBox; cb.MouseLeftButtonUp -= MouseLeftButtonUp_CreateArrow; } } canvas.MouseLeftButtonUp -= MouseLeftButtonUp_CreateArrow; }
private void MouseMove_groupClassBox(object sender, MouseEventArgs e) { if (sender is ClassBox) { ClassBox moveObject = (ClassBox)sender; Point point = e.GetPosition(canvas); double x = point.X; double y = point.Y; if (x < mouseMinX) { x = mouseMinX; } else if (x > mouseMaxX) { x = mouseMaxX; } if (y < mouseMinY) { y = mouseMinY; } else if (y > mouseMaxY) { y = mouseMaxY; } Point classBoxPoint = moveObject.TransformToAncestor(canvas).Transform(new Point(0, 0)); Point pt = new Point(classBoxPoint.X + moveObject.ActualWidth / 2, classBoxPoint.Y + moveObject.ActualHeight / 2); moveObject.linkPoint = pt; foreach (ArrowLine arrow in moveObject.arrowLinesTo) { arrow.X2 = moveObject.linkPoint.X; arrow.Y2 = moveObject.linkPoint.Y; } foreach (ArrowLine arrow in moveObject.arrowLinesFrom) { arrow.X1 = moveObject.linkPoint.X; arrow.Y1 = moveObject.linkPoint.Y; } double top = beginTop + y; double left = beginLeft + x; Canvas.SetLeft(moveObject, left); Canvas.SetTop(moveObject, top); } }
private void MouseLeftButtonDown_CreateArrow(object sender, MouseButtonEventArgs e) { if (sender is ClassBox) { ClassBox classBox = (ClassBox)sender; if (arrow.X1 == 0 && arrow.X2 == 0) { Point classBoxPoint = classBox.TransformToAncestor(canvas).Transform(new Point(0, 0)); Point pt = new Point(classBoxPoint.X + classBox.ActualWidth / 2, classBoxPoint.Y + classBox.ActualHeight / 2); arrow.X1 = pt.X; arrow.Y1 = pt.Y; arrow.X2 = pt.X; arrow.Y2 = pt.Y; canvas.MouseMove += MouseMove_ArrowDrawing; canvas.Children.Add(arrow); classBox.arrowLinesFrom.Add(arrow); } } }