internal void AddConnect(Connect connect) { ArrowLineWithText arrow = new ArrowLineWithText(); arrow.MouseDown += arrow_MouseDown; arrow.MouseMove += arrow_MouseMove; arrow.MouseUp += arrow_MouseUp; arrow.Tag = connect; Panel parent = this.Parent as Panel; DescriptionView target = null; foreach (FrameworkElement item in parent.Children) { if (item.Equals(this) == false && item is DescriptionView) { target = item as DescriptionView; if (target.InterfaceInModule.id == connect.ToWhere) { break; } target = null; } } if (target == null) { return; } if (connect.ArrowFromWhere == ArrowFromWhere.LeftRight) { if (target.Margin.Left > this.Margin.Left) { arrow.StartPoint = new Point(this.ActualWidth, connect.y1); Point p = target.TranslatePoint(new Point(0, connect.y2), this); arrow.EndPoint = new Point(p.X, p.Y); } else { arrow.StartPoint = new Point(0, connect.y1); Point p = target.TranslatePoint(new Point(target.ActualWidth, connect.y2), this); arrow.EndPoint = new Point(p.X, p.Y); } } else { if (target.Margin.Top > this.Margin.Top) { arrow.StartPoint = new Point(connect.x1, this.ActualHeight); Point p = target.TranslatePoint(new Point(connect.x2, 0), this); arrow.EndPoint = new Point(p.X, p.Y); } else { arrow.StartPoint = new Point(connect.x1, 0); Point p = target.TranslatePoint(new Point(connect.x2, target.ActualHeight), this); arrow.EndPoint = new Point(p.X, p.Y); } } arrow.Stroke = Brushes.Blue; arrow.StrokeThickness = 1; arrow.Cursor = Cursors.Hand; arrow.TextAlignment = TextAlignment.Center; arrow.Margin = new Thickness(0, 0, -100000, -10000000); arrow.IsTextUp = true; arrow.Text = connect.Text; m_grid.Children.Add(arrow); }
internal bool ResetConnect(Connect connect) { ArrowLineWithText arrow = null; foreach (var item in m_grid.Children) { if (item is ArrowLineWithText) { arrow = (ArrowLineWithText)item; if (arrow.Tag == connect) { break; } arrow = null; } } if (arrow == null) { return(false); } Panel parent = this.Parent as Panel; DescriptionView target = null; foreach (FrameworkElement item in parent.Children) { if (item.Equals(this) == false && item is DescriptionView) { target = item as DescriptionView; if (target.InterfaceInModule.id == connect.ToWhere) { break; } target = null; } } if (target == null) { //目标没有了,留个箭头干嘛 m_grid.Children.Remove(arrow); return(false); } if (connect.ArrowFromWhere == ArrowFromWhere.LeftRight) { if (target.Margin.Left > this.Margin.Left) { arrow.StartPoint = new Point(this.ActualWidth, connect.y1); Point p = target.TranslatePoint(new Point(0, connect.y2), this); arrow.EndPoint = new Point(p.X, p.Y); } else { arrow.StartPoint = new Point(0, connect.y1); Point p = target.TranslatePoint(new Point(target.ActualWidth, connect.y2), this); arrow.EndPoint = new Point(p.X, p.Y); } } else { if (target.Margin.Top > this.Margin.Top) { arrow.StartPoint = new Point(connect.x1, this.ActualHeight); Point p = target.TranslatePoint(new Point(connect.x2, 0), this); arrow.EndPoint = new Point(p.X, p.Y); } else { arrow.StartPoint = new Point(connect.x1, 0); Point p = target.TranslatePoint(new Point(connect.x2, target.ActualHeight), this); arrow.EndPoint = new Point(p.X, p.Y); } } if (!string.IsNullOrEmpty(arrow.Text)) { arrow.InvalidateVisual(); } return(true); }