private void ClassBox_MouseEnter(object sender, MouseEventArgs e) { if (sender is ClassBox) { classBox = (ClassBox)sender; } }
private void MouseLeftButtonDown_groupClassBox(object sender, MouseButtonEventArgs e) { if ((sender is ClassBox)) { ClassBox moveObject = (ClassBox)sender; if (moveObject.Parent is Canvas) { beginTop = Canvas.GetTop(moveObject); beginLeft = Canvas.GetLeft(moveObject); mouseMaxX = canvas.Width - moveObject.Width; mouseMaxY = canvas.Height - moveObject.Height; Point point = e.GetPosition(moveObject); mouseMaxX += point.X; mouseMaxY += point.Y; point = e.GetPosition(canvas); beginLeft -= point.X; beginTop -= point.Y; moveObject.MouseMove += MouseMove_groupClassBox; } } }
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 MouseLeftButtonUp_GroupBoxMove(object sender, MouseButtonEventArgs e) { if (sender is ClassBox) { ClassBox moveObject = (ClassBox)sender; moveObject.MouseMove -= MouseMove_groupClassBox; } }
private void button1_Click(object sender, RoutedEventArgs e) { ClassBox cl = new ClassBox(); cl.MouseLeftButtonDown += MouseLeftButtonDown_groupClassBox; cl.MouseLeftButtonUp += MouseLeftButtonUp_GroupBoxMove; cl.MouseEnter += ClassBox_MouseEnter; canvas.Children.Add(cl); }
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 CreateLinkBetweenClassBoxes() { arrow = new ArrowLine(); arrow.Stroke = Brushes.White; arrow.StrokeThickness = 5; foreach (object obj in canvas.Children) { if (obj is ClassBox) { ClassBox classBox = (ClassBox)obj; classBox.MouseLeftButtonDown -= MouseLeftButtonDown_groupClassBox; classBox.MouseLeftButtonDown += MouseLeftButtonDown_CreateArrow; classBox.MouseLeftButtonUp += MouseLeftButtonUp_CreateArrow; } } canvas.MouseLeftButtonUp += MouseLeftButtonUp_CreateArrow; }
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); } } }